6

We're in the process of converting a 15-year-old application into C#/Entity Framework Code First.

I've been able to create a migration for the table structures that I'll need, and I'd like to fill them with the data from our old application. Of course, it's possible to simply create a script using Management Studio, but I'd like to leverage Code First if possible.

I see that it's possible to reverse engineer a database schema. Is there a simple way that I could generate a migration or Seed method from existing data in a database? I'm not too worried about performance - it's enough data to be a pain to recreate by hand, but neither are we talking about thousands of rows.

1 Answer 1

4

Entity Framework itself should not be used for mass insertion/deletion/updating of records since the performance is really poor. If you want the seeding to be part of your migrations then you could include your SqlCommands inside your Seed method:

protected override void Seed(Context context)
{
   context.Database.ExecuteSqlCommand("Command Here");
}
base.Seed(context);
Sign up to request clarification or add additional context in comments.

3 Comments

I'm not too worried about performance - it's complex enough data to be a pain to recreate by hand, but neither are we talking about thousands of rows. I may just dump into all into a string literal, then, if that's really the best option.
is your data currently in a sql server db? if it is you could use the Generate Scripts feature.
That looks like the most reasonable option. Thanks.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.