13

I watched a screencast from MSDN BLOG that talks about database migration.

Is there anyone who knows when can we use this feature? It looks it doesn't work in CTP5 yet.

By the way, is there any way to seed the initial data after I changed the schema code?

This is what am I doing right now, it wipes all the data every time I altered the model.

DbDatabase.SetInitializer<Context>(
    new DropCreateDatabaseIfModelChanges<Context>());
1
  • 5
    i'll vote you up just for you not to have '666' as your reputation anymore.... that can't be good ;) Jan 16, 2011 at 2:41

3 Answers 3

10

They most likely get this migration feature in the RTM version which is targeted for the first quarter of 2011.

To populate database with some initial data you can create your own database initializer and have it inherit from your desired strategy (right now we have 2 options) and then override Seed method inside it:

public class MyInitializer : DropCreateDatabaseIfModelChanges<MyContext>
{
    protected override void Seed(InheritanceMappingContext context)
    {        
        MyEntity entity = new MyEntity()
        {
            ...
        };
        context.MyEntities.Add(entity);
        context.SaveChanges();
    }
}
3
  • Morteza, what assembly is the DropCreateDatabaseIfModelChanges in? I am trying to follow the ASP.Net tutorial on creating the Music Store and they're using the same call and I get an exception:
    – clockwiseq
    Mar 20, 2011 at 2:57
  • I'm guessing the migration feature hasn't been added to EF as of this writing? Jun 14, 2011 at 15:49
  • No, it has been cut off from the 4.1 RTW and is targeted for the next EF release. The team is actively working on this feature and showed a preview of it in the TechEd 2011. Jun 14, 2011 at 16:17
1

Alpha 3 is out now. http://blogs.msdn.com/b/adonet/archive/2011/09/21/code-first-migrations-alpha-3-no-magic-walkthrough.aspx

0

EF 4.1 Candidate Release has been issued in March and looks like this Migration feature is not yet included

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.