问题
I created a model in the edm designer (VS10) using "DbContext Entity Generator" as the generation item.
In the generated DbContext subclass, it overrode the constructor so I can't use it in the other partial class:
public EntitiesContainer()
: base("name=EntitiesContainer")
{
this.Configuration.LazyLoadingEnabled = false;
}
What's the proper way of initialize a database with model-first?
回答1:
You could alter the T4 template that's being used for generating the DbContxt class. Then you could add the partial modifiers or methods that you want to use to initialize your context.
回答2:
There is no automatic database initialization when using model first. You must generate SQL script from the model (use context menu in EDMX designer and choose Generate database from model) and execute it yourselves on existing database.
SetInitializer
is only for code first.
来源:https://stackoverflow.com/questions/8206058/how-to-call-database-setinitializer-on-model-first