SamWM
SamWM

Reputation: 5356

Entity Framework - OnModelCreating with Model First

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.

Upvotes: 1

Views: 6760

Answers (2)

Rory
Rory

Reputation: 41807

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.

Upvotes: 1

Ladislav Mrnka
Ladislav Mrnka

Reputation: 364269

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

Upvotes: 3

Related Questions