I have the fallowing NHibernate-Mapping:
<class name="Activity" table="Activity" lazy="false" >
<cache usage="read-write"/>
<id name="Id" column="Id" type="Guid">
<generator class="assigned"/>
</id>
<property name="Subject" column="Subject" type="String" length="255" />
<many-to-one name="ParentActivity" class="Activity" foreign-key="FK_Activity_ParentActivity" lazy="proxy" fetch="select">
<column name="ParentActivityId"/>
</many-to-one>
<set name="Activities" lazy="true" inverse="true" cascade="none" >
<key>
<column name="ParentActivityId"/>
</key>
<one-to-many class="Activity"/>
</set>
I have now an Entity Activity (x) which has another Entity Activity (y) set as ParentActivity. I am searching for the solution, that, when I delete the entity y, the reference from x to y is set to null. Now I become an error, that I cannot delete x because of the FK_Activity_ParentActivity. Can someone point me to the right way how I can do this? - Thanks.
Maybe this post of Ayende Rahien will help you: the different between all all-delete-orphans and save-update
Here is what each cascade option means:
- none - do not do any cascades, let the users handles them by themselves.
- save-update - when the object is saved/updated, check the associations and save/update any object that require it (including save/update the associations in many-to-many scenario).
- delete - when the object is deleted, delete all the objects in the association.
- delete-orphan - when the object is deleted, delete all the objects in the association. In addition to that, when an object is removed from the association and not associated with another object (orphaned), also delete it.
- all - when an object is save/update/delete, check the associations and save/update/delete all the objects found.
- all-delete-orphan - when an object is save/update/delete, check the associations and save/update/delete all the objects found. In additional to that, when an object is removed from the association and not associated with another object (orphaned), also delete it.