gpt4 book ai didi

c# - NHibernate - 在删除时将引用设置为空

转载 作者:太空宇宙 更新时间:2023-11-03 14:09:45 25 4
gpt4 key购买 nike

我有休闲的 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>

我现在有一个实体事件 (x),它有另一个实体事件 (y) 设置为 ParentActivity。我正在寻找解决方案,当我删除实体 y 时,从 x 到 y 的引用设置为 null。现在我变成了一个错误,因为 FK_Activity_ParentActivity,我无法删除 x。有人可以指出我如何做到这一点的正确方法吗? - 谢谢。

最佳答案

也许 Ayende Rahien 的这篇文章会对您有所帮助: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.

关于c# - NHibernate - 在删除时将引用设置为空,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8232417/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com