我有一个单向多对多关联: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>
发布评论
评论(1)
您确定“ all-delete-orphan” 是你想要的吗?
来自第 21.3 节。上述链接的级联生命周期:
Are you sure "all-delete-orphan" is what you want?
From Section 21.3. Cascading life cycle of the above link: