多重约束违规调试
我的实体模型中出现多重约束违规。
在我的实体模型上,我有两个关系属性:
- SubstanceTypeMixConstituents
- 类别
SubstanceTypeMixConstituents
- 多重性*(许多)
类别
- 多重性:1(一)
- 外键,非空
如何找到导致问题的原因并解决此问题?
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()
I'm getting a multiplicity constraint violation in my entity model.
On my entity model I have two relationship properties:
- SubstanceTypeMixConstituents
- Category
SubstanceTypeMixConstituents
- Multiplicity * (Many)
Category
- Multiplicity: 1 (One)
- Foreign key, not null
How do I find what causing the problem and resolve this issue?
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()
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
据我了解,您有两个实体 -
Category
和SubstanceTypeMixConstituent
,它们具有一对多
关系 -Category
可以有多个SubstanceTypeMixConstituent
,但一个SubstanceTypeMixConstituent
只能有(且必须有)一个Category
(如果我错了,请纠正我) )。您收到的错误消息的含义与它所说的完全一样 - 您要么尝试使用SubstanceTypeMixConstituents
的空集合保存Category
,要么保存SubstanceTypeMixConstituent
没有类别
。As far as I understand, you have two entities -
Category
andSubstanceTypeMixConstituent
which have aOne-to-many
relationship - aCategory
can have multipleSubstanceTypeMixConstituents
, but aSubstanceTypeMixConstituent
can have (and must have) only oneCategory
(correct me if I am wrong). The error message you get means exactly what it says - you are either trying to save aCategory
with an empty collection ofSubstanceTypeMixConstituents
, or aSubstanceTypeMixConstituent
without aCategory
.