1

我将 NHibernate 3.2 与 MS SQL Server 2008 R2 一起使用

我有休闲映射

<class name="LocalizedProperty" table="LocalizedProperty">
   <cache usage="read-write"/>
   <id name="Id" column="Id">
      <generator class="guid.comb"/>
   </id>
   <property name="CultureName"  not-null="true"/>
   <property name="PropertyName"  not-null="true"/>
   <property name="PropertyValue"  not-null="true"/>

   <any id-type="Guid" name="Entity">
      <column name="LocalizedEntityClass"  not-null="true"/>
      <column name="EntityId"  not-null="true"/>
   </any>
</class>

这个有一个对 LocalizedProperty 的引用:

<class name="CommunicationType" table="CommunicationType" lazy="false"  >
...
<set name="LocalizedProperties" where="LocalizedEntityClass = 'Prayon.Entities.CommunicationType'" cascade="delete">
  <key column="EntityId" foreign-key="none" />
  <one-to-many class="LocalizedProperty" />
</set>
</class>

我的问题是,当我删除 CommunicationType 的实体时,NHibernate 正在执行 LocalizedProperty 的休闲更新语句

UPDATE LocalizedProperty SET EntityId = null WHERE EntityId = @p0 AND (LocalizedEntityClass = 'Prayon.Entities.CommunicationType')

而不是删除语句。

有人看到了吗,怎么了?

4

2 回答 2

2

要删除表的子元素,您需要指定cascade="all-delete-orphan"

<bag name="TableClassName" table="TableClassName" cascade="all-delete-orphan" >
    <key column="PrimaryKey"/>
    <one-to-many class="NameSpace.TableClassName" />

于 2011-12-30T20:37:36.103 回答
0

如果您放置一个 all-delete-orphan,则问题是全部部分。它将级联所有操作,而不仅仅是删除。

于 2015-09-10T19:01:27.630 回答