2011-12-30 2 views
1

작동하지 않습니다 삭제할 ​​2008 R2NHibernate에 - 캐스케이드 내가 MS SQL Server에 NHibernate에 3.2를 사용

나는 fallowing 매핑

<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의 fallowing update-statement를 실행 중입니다.

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

Delete-Statement 대신.

누군가가 뭘 잘못 보았습니까?

답변

2

테이블의 하위 요소를 삭제하려면 cascade = "all-delete-orphan"을 지정해야합니다.

0

당신은 문제가 모든 부분 인 모두 삭제 - 고아를 넣으면

<bag name="TableClassName" table="TableClassName" cascade="all-delete-orphan" > 
    <key column="PrimaryKey"/> 
    <one-to-many class="NameSpace.TableClassName" /> 
. 삭제 작업뿐만 아니라 모든 작업을 계단식으로 처리합니다.