多重约束违规调试

发布于 2024-11-05 02:46:58 字数 1143 浏览 0 评论 0原文

我的实体模型中出现多重约束违规。

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

  1. SubstanceTypeMixConstituents
  2. 类别

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:

  1. SubstanceTypeMixConstituents
  2. Category

SubstanceTypeMixConstituents
- Multiplicity * (Many)
Category
- Multiplicity: 1 (One)
- Foreign key, not null

enter image description here

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

还不是爱你 2024-11-12 02:46:58

据我了解,您有两个实体 - CategorySubstanceTypeMixConstituent,它们具有 一对多 关系 - Category 可以有多个 SubstanceTypeMixConstituent,但一个 SubstanceTypeMixConstituent 只能有(且必须有)一个 Category(如果我错了,请纠正我) )。您收到的错误消息的含义与它所说的完全一样 - 您要么尝试使用 SubstanceTypeMixConstituents 的空集合保存 Category,要么保存 SubstanceTypeMixConstituent没有类别

As far as I understand, you have two entities - Category and SubstanceTypeMixConstituent which have a One-to-many relationship - a Category can have multiple SubstanceTypeMixConstituents, but a SubstanceTypeMixConstituent can have (and must have) only one Category (correct me if I am wrong). The error message you get means exactly what it says - you are either trying to save a Category with an empty collection of SubstanceTypeMixConstituents, or a SubstanceTypeMixConstituent without a Category.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文