Entity Framework Exception: Ambiguous match found

纵然是瞬间 提交于 2019-12-04 03:26:08

问题


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?


回答1:


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.




回答2:


Although this is probably a much less likely scenario, but we were running EF Core 1.0 which had only one version of the Include() method... in version 1.1, Microsoft added a second implementation (the string version) and since we were calling this method dynamically we got this error after updating our EF Core to 1.1



来源:https://stackoverflow.com/questions/18245686/entity-framework-exception-ambiguous-match-found

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!