Entity Framework - OnModelCreating with Model First

主宰稳场 提交于 2019-11-28 10:47:09

问题


I have a Entity Framework model set up with text templates to generate the code. However, one of them creates the DBContext containing an OnModelCreating.

    protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {
        throw new UnintentionalCodeFirstException();
    }

How do expand on this, since a partial class with the same override does not work.


回答1:


You cannot use OnModelCreating when using model first (EDMX). OnModelCreating is only for scenarios without using EDMX.




回答2:


Possibly your problem is that the connection string you're using is a standard SQL Server one rather than the Entity Framework one. See this answer.



来源:https://stackoverflow.com/questions/7189624/entity-framework-onmodelcreating-with-model-first

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