1

MS SQL Server 2008 R2 で NHibernate 3.2 を使用しています

私は以下のマッピングを持っています

<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-statement を実行していることです。

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 に答える