开发者

EntityFramework throws AmbiguousMatchException

The setup: EntityFramework POCO with proxies (+LazyLoading)

Component and Part classes both implement IDataErrorInfo (if this is necessary). The following code throws exception:

// Context is a singleton here
Context.LoadProperty<Part>(
    partEntity, 
    (e) => e.ChildComponents, 
    MergeOption.OverwriteChanges);

The ambiguous property is ChildComponents as I can tell yet there is no other property with the same name, its only definition is:

public virtual ICollection<Component> ChildComponents { get; set; }

This is overridden in EF proxy and changed into something like

public virtual EntityCollection<Component> ChildComponents { get; set; }

Yet t开发者_C百科his issue just appeared and I cannot understand why now as there were no real changes.


I have investigated this matter and turns out that .NET compiles indexers (e.g. from IDataErrorInfo) into Item, therefore introducing some kind of ambiguousness in a class that is called Item and any classes that have such a property. That causes problems in EF. This problem is buried in my code more deeply than I thought and not all info is present in initial post (mainly the fact that Component class has an Item property).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜