从 NHibernate 中的多对多关联中删除项目

发布于 2024-09-18 18:59:17 字数 1632 浏览 0 评论 0 原文

我有一个单向多对多关联:ListDefinition 类具有 IList 类型的 Columns 属性,而一列可以是多个 ListDefinition 的一部分。问题是,每当我尝试从一个 Columns 集合中删除一列(不删除它或从其他 ListDefinitions 中删除)时,我都会收到此错误:
已删除的对象将通过级联重新保存(从关联中删除已删除的对象)[Domain.Lists.Definitions.ListColumnDefinition#2]

我的映射是通过 Fluent NH 生成的:

mapping.HasManyToMany(list => list.Columns)
.AsList(part => part.Column("`index`"))
.Cascade.AllDeleteOrphan()

这是生成的 hbm:




<列名=“Id”/>
<生成器类=“身份”/>


<键>
<列名=“ListDefinition_id”/>
<索引>
<列名=“索引”/>


<列名=“ListColumnDefinition_id”/>

I have a one-directional many-to-many association: the ListDefinition class has the Columns property of type IList, while a column can be part of several ListDefinition-s. The problem is, whenever I try to remove a column from one Columns collection (without deleting it or removing from other ListDefinitions), I'm getting this error:
deleted object would be re-saved by cascade (remove deleted object from associations)[Domain.Lists.Definitions.ListColumnDefinition#2]

My mapping is generated via Fluent NH:

mapping.HasManyToMany(list => list.Columns)
.AsList(part => part.Column("`index`"))
.Cascade.AllDeleteOrphan()

Here's the generated hbm:

<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" default-access="property" auto-import="true" default-cascade="all" default-lazy="false">
<class xmlns="urn:nhibernate-mapping-2.2" mutable="true" name="Domain.Lists.Definitions.ListDefinition, Domain, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" table="ListDefinition">
<id access="nosetter.camelcase-underscore" name="Id" type="System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<column name="Id" />
<generator class="identity" />
</id>
<list cascade="all-delete-orphan" name="Columns" table="ListColumnDefinitionToListDefinition" mutable="true">
<key>
<column name="ListDefinition_id" />
</key>
<index>
<column name="index" />
</index>
<many-to-many class="Domain.Lists.Definitions.ListColumnDefinition, Domain, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null">
<column name="ListColumnDefinition_id" />
</many-to-many>
</list>

</class>
</hibernate-mapping>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(1

-残月青衣踏尘吟 2024-09-25 18:59:17

您确定“ all-delete-orphan” 是你想要的吗?

来自第 21.3 节。上述链接的级联生命周期:

在我们的例子中,Child 不可能存在
没有它的父级。所以如果我们删除一个
收藏中的孩子,我们确实想要
将其删除。为此,我们必须
使用级联=“all-delete-orphan”。

Are you sure "all-delete-orphan" is what you want?

From Section 21.3. Cascading life cycle of the above link:

In our case, a Child cannot exist
without its parent. So if we remove a
Child from the collection, we do want
it to be deleted. To do this, we must
use cascade="all-delete-orphan".

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