سؤال

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>());
هل كانت مفيدة؟

المحلول

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();
    }
}

نصائح أخرى

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

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top