SubstanceTypeMixConstituent

SubstanceTypeMixConstituent

我的实体模型中遇到多重约束违规。

在我的实体模型上,我有两个关系属性:

  • SubstanceTypeMix成分
  • 类别

  • 物质类型混合成分
    -多重*(很多)
    类别
    -多重性:1(一个)
    -外键,不为null

    如何找到导致问题的原因并解决此问题?
    System.InvalidOperationException: A relationship multiplicity constraint violation occurred: An EntityReference expected at least one related object, but the query returned no related objects from the data store.
       at System.Data.Objects.DataClasses.EntityReference`1.Load(MergeOption mergeOption)
       at System.Data.Objects.DataClasses.RelatedEnd.DeferredLoad()
       at System.Data.Objects.Internal.LazyLoadBehavior.LoadProperty[TItem](TItem propertyValue, String relationshipName, String targetRoleName, Boolean mustBeNull, Object wrapperObject)
       at System.Data.Objects.Internal.LazyLoadBehavior.<>c__DisplayClass7`2.<GetInterceptorDelegate>b__2(TProxy proxy, TItem item)
       at System.Data.Entity.DynamicProxies.SubstanceType_BEE32ACA75386E981F7CA3F6A3C565BC1D8ADACA228C603A2EACC918DCDCBA30.get_Category()
    

    最佳答案

    据我了解,您有两个具有Category关系的实体-SubstanceTypeMixConstituentOne-to-many-Category可以具有多个SubstanceTypeMixConstituents,但是SubstanceTypeMixConstituent只能(必须必须)有一个Category(如果我错了,请纠正我)。您收到的错误消息的含义与所说明的完全相同-您正在尝试保存带有空Category集合的SubstanceTypeMixConstituents,或者尝试不包含SubstanceTypeMixConstituentCategory

    09-07 01:52