Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Entity Framework Exception: Ambiguous match found

I get the error:

Ambiguous match found

During this code on the .Add

var db = new NexusEntities(); 
db.Reports.Add(mmr);

From googling it appears to be an issue if the there are two classes with the same name but in different namespaces. As far as I can tell this is not the case... Is there another reason why this error can happen? Or is there a way to tell which parameter it is finding two of?

like image 840
Kyle Avatar asked Aug 15 '13 03:08

Kyle


1 Answers

This is a "weakness" in EF. It happens when the same property appears in class / subtype hierarchy.

Most likely you have a hidden field. i.e. a property that has been redefined. When EF looks for the a property it too must use the type/base tree to find the property. But if it finds it twice in the tree, it interprets this as a duplicate. EF doesnt just use the lowest most specific override.

So property hiding is not possible with EF.

Check your classes, a property will occur twice somewhere.

like image 63
phil soady Avatar answered Sep 25 '22 15:09

phil soady