开发者

Entity Framework - OnModelCreating with Model First

开发者 https://www.devze.com 2023-03-30 10:49 出处:网络
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.

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 O开发者_Python百科nModelCreating(DbModelBuilder modelBuilder)
    {
        throw new UnintentionalCodeFirstException();
    }

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


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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消