我在Entity Framework 4中加载了对父对象的引用的麻烦.由于Lazy加载对父对象(Condition)的引用没有加载到子对象(DiscountLevel)上,所以我尝试加载它:
if(!this.ConditionReference.IsLoaded) this.ConditionReference.Load();
但这会抛出以下异常:
the entity reference could not be loaded because it is not attached to an objectcontext
因此,如果我尝试将现有的子对象(DiscountLevel)附加到对象上下文中(然后再加载父参考):
context.AttachTo("tblDiscountLevel",this);
我得到以下例外:
An object with the same key already exists in the ObjectStateManager. The existing object is in the Detached state. An object can only be added to the ObjectStateManager again if it is in the added state.
我觉得我第一次做错了,但我无法弄明白什么.所以对这个话题的每一个帮助都非常感激.如果您需要更多信息,请告诉我们!