How can I disable migration in Entity Framework 6.0

后端 未结 7 1561
傲寒
傲寒 2020-11-29 01:24

I\'m trying to ignore the \"Automatic\" migration using Entity Framework 6.0 rc1. My problem is that I don\'t want this feature right now and every time that my application

7条回答
  •  误落风尘
    2020-11-29 02:00

    The mistake I was making was to call Database.SetInitializer(null); too late (after the context had been initialised). The best way to ensure migrations are disabled is to make the above call for all your contexts in your application startup. I favor this approach over setting it in the app.config so I can use my container to locate my contexts and then construct a call.

    var migrationsMethod = typeof(System.Data.Entity.Database).GetMethod("SetInitializer");
    foreach (var contextType in allContextTypes)
    {
        migrationsMethod.MakeGenericMethod(contextType).Invoke(null, new object[] { null });                            
    }
    

提交回复
热议问题