How to call Database.SetInitializer on model-first?

假如想象 提交于 2020-01-02 06:31:29

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!