我将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')
而不是删除声明。
有人看到了,出了什么问题?
答案 0 :(得分:2)
要删除表格的子元素,您需要指定 cascade =“all-delete-orphan”。
<bag name="TableClassName" table="TableClassName" cascade="all-delete-orphan" >
<key column="PrimaryKey"/>
<one-to-many class="NameSpace.TableClassName" />