Confusion over EF Auto Migrations and seeding - seeding every program start

前端 未结 3 1691
渐次进展
渐次进展 2020-12-04 12:23

I recently changed an application from using the following for dev:

DropCreateDatabaseIfModelChanges


To using:

3条回答
  •  有刺的猬
    2020-12-04 12:53

    Another option might be to load a custom db initializer class at runtime within the seed method. The Production app could then load a dummy initializer, while the dev app could load the real initializer. You could use Unity/MEF

        // Unity Dependency Injection Prop
        [Dependency]
        property IMyInitializer initializer;
    
        protected override Seed(YourContextClass context)
        {
           initializer.Seed(context);
        }
    

    Something like that. You'd then switch initializers once you have the DB set-up in Production, to the dummy one, that would do nothing.

提交回复
热议问题