If you want to turn off database initialization/migration completely regardless of in which project you re using your Context you can add a static constructor to your context to call the initializer.
This ensures that the SetInitializer will be called once prior to the first construction/use of your context.
public class YourContext : DbContext
{
static YourContext()
{
// don t let EF modify the database schema...
Database.SetInitializer<YourContext >(null);
}
public YourContext() : base("name=YourContext")
{}
...
}
然而,如果您只想在选定的几个项目中这样做,您最好通过应用程序启动来明确这样做,例如,在您正常的 IoC 设置期间,如Ladislav 所建议的那样。