包上的休眠级联删除 [英] Hibernate cascade delete on a bag

查看:66
本文介绍了包上的休眠级联删除的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在使用 NHibernate 构建了我的大部分 DAL 之后,我现在发现 SQL Server 的 Cascade On Delete 规则也需要在我的 HBM 文件中考虑在内.我一直在为我的所有系列使用包,但似乎没有办法为包添加级联 =删除"属性.我可以将所有包更改为集合,但这似乎意味着我已将模型上的所有 IList<> 更改为 PersistentGenericSet<>,我并不喜欢这样做.

Having built most of my DAL using NHibernate, I've now discovered that the SQL Server's Cascade On Delete rules also need to be taken into account in my HBM files too. I've been using bags for all my collections, but there doesn't seem to be a way to add a cascade="delete" attribute to a bag. I can change all my bags to sets, but that appears to mean I have changing all my IList<>s on my models to PersistentGenericSet<>s, which I don't really fancy doing.

有什么建议吗?

安东尼

推荐答案

有两个独立但相关的概念:NHibernate 的级联规则和 DB 级联.

There are two separate-but-related concepts: NHibernate's cascading rules, and DB cascading.

后者实际上是在 key 元素上配置的,所以,如果 FK 有 ON DELETE CASCADE,这就是包的样子:

The latter is actually configured on the key element so, if the FK has ON DELETE CASCADE, this is what the bag should look like:

<bag name="Children" ...>
  <key column="ParentId" on-delete="cascade"/>
  <one-to-many class="Child"/>
</bag>

这篇关于包上的休眠级联删除的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆