"object type is not part of the model for the current context" an error occurs when the project contains more than one EDMX file

First, I use a database, and I have a switch that looks something like this:

 switch (site) { case Site.One: using (OneContext one = new OneContext()) return one.OrganizationObjects.SingleOrDefault(x => x.u_Name == orgName)?.g_org_id; case Site.Two: using (TwoContext two = new TwoContext()) return two.OrganizationObjects.SingleOrDefault(x => x.u_Name == orgName)?.g_org_id; default: throw new NotImplementedException(); } 

Both databases are pretty similar and have almost all of the same models.

If I delete the Two EDMX file and comment out this condition, OneContext works fine.
If I add the TwoContext EDMX file to the project and run the code again, the "OneContext" code will fail when it tries to query OrganizationObjects.

I made sure that each context uses the correct connection string, but this error still occurs:

enter image description here

+7
c # entity-framework ef-database-first
source share
2 answers

Workaround: Change the property to one of two identical classes.

EF matches class and class properties. So I just changed the name of the property on one of the EF objects and the error went away.

As @Entrodus commented on one of the other answers:

An EF collision occurs only when two classes have the same name. the same set of parameters.

Is an EDM type CLR mapping ambiguous with EF 6 and 5?

+3
source share

Entity Framework corresponds to the properties of the class and class. Two classes with the same class name and the same properties lead to conflict.

Changing a property on one of two identical classes will solve the problem.

0
source share

All Articles