DbContext.OnModelCreating is not called, when I modify MYENTITY to MyEntitity

1.1k views Asked by At

I have a large solution that is using classic Entity Framework.

I am in the process of adding the Fluent API, which relies on mappings that are defined in DbContext.OnModelCreating. When run this from UnitTest project all is well, because that doesn't have the EDMX defined.

my main web project is still using EDMX (may not go away for a while) and i am adding some views that are using Fluent API. However, when i open my views i see that OnModelCreating is never called, and therefore all the fluent mappings i introduced are never added.

i do have separate connection strings defined for EDMX, and the DbContext.

how can i ensure OnModelCreating is called, even from an app that uses classic EDMX model?

UPDATE

as long as the name of my Entity class is the same as the name of the table, OnModelCreating is called from my main site!! this is very confusing.. as soon as i change the case of the class (MYENTITY to MyEntity), OnModelCreating is no longer called!!, and therefore all the mappings are not applied so the get fails..

UPDATE 2

Astoundingly, the same thing happens if I try to rename a property.

If I change the property on my entity object from SHORT_NAME to ShortName, and update my definition in OnModelCreating ...

modelBuilder.Entity<MYOBJECT>()
            .Property(f => f.ShortName)
            .HasColumnName("SHORT_NAME");

but OnModelCreating never gets called

0

There are 0 answers