Posts
1150
Comments
891
Trackbacks
1
EF doesn’t really like bounded contexts

So, from the previous post on the subject, I randomly tried Phillip’s suggestion of dropping the models in different folders, and was rather surprised that it could now build.  Great!!!!

Except….no.  At run time, a new error surfaced:

System.Data.Entity.Core.MetadataException was unhandled
  HResult=-2146232007
  Message=Schema specified is not valid. Errors:
The mapping of CLR type to EDM type is ambiguous because multiple CLR types match the EDM type 'Cart'. Previously found CLR type 'EF6CommonTable.Model.Checkout.Cart', newly found CLR type 'EF6CommonTable.Model.Shopping.Cart'.
The mapping of CLR type to EDM type is ambiguous because multiple CLR types match the EDM type 'CartItem'. Previously found CLR type 'EF6CommonTable.Model.Checkout.CartItem', newly found CLR type 'EF6CommonTable.Model.Shopping.CartItem'.
 

Uh, what the hell?

After doing some research, it appears that this is by design, and has been present in EF from the beginning, but since I was using the Legacy ObjectContext, I never ran into it.

It might be fixed in the future.

Basically, EF ignores namespaces, so it is failing because the class names are identical.  ‘Workarounds’ involve changing the names, putting each model in its own project (though I’ve read that might not always work from some comments), etc.

This……seems idiotic.

I’m not sure what I will do here.

posted on Wednesday, July 30, 2014 1:12 PM Print
Comments
Gravatar
# re: EF doesn’t really like bounded contexts
Jarkynai
12/3/2014 5:52 AM
Please Could U help me with such problem?

I'm loooking for such bug, but didn't find

ErrorSystem.Data.Entity.Core.MetadataException: Schema specified is not valid. Errors: The mapping of CLR type to EDM type is ambiguous because multiple CLR types match the EDM type 'Cart'. Previously found CLR type 'Cart', newly found CLR type 'JarkinayDBModel.Cart'.
Gravatar
# re: EF doesn’t really like bounded contexts
jdn
12/3/2014 9:36 AM
@Jarkynai:

It appears to be exactly what I'm talking about. You are referencing the same table in two different models in the same project, and the latest versions of EF doesn't like that.

You have to create the models in different projects.
Gravatar
# re: EF doesn’t really like bounded contexts
Jarkynai
12/4/2014 3:25 AM
But I'm using EF 6 version
Gravatar
# re: EF doesn’t really like bounded contexts
jdn
12/4/2014 9:41 AM
@Jarkynai:

That's exactly the point. This is how EF 6 works. Specifically, it is how the templates work, and you can no longer use the LegacyObjectContext to get around it the old way.

Post Comment

Title *
Name *
Email
Url
Comment *  
Please add 3 and 5 and type the answer here: