如何在 HQL 中给定子 ID 的情况下从父级中删除一对多子级
我
class Parent
{
IList<Child> Children;
}
class Child
{
}
在删除 Child
时,需要从引用它的任何 Parents
中删除对它的所有引用。
我怎样才能在 NHibernate 中做到这一点?
Child
上没有 Parent
FK
,关系存储在第三个“链接”表中,
谢谢
I've got
class Parent
{
IList<Child> Children;
}
class Child
{
}
When deleting a Child
I need to remove all references to it from any Parents
that reference it.
How can I do this in NHibernate?
There is no Parent
FK
on Child
, the relationship is stored in a 3rd "link" table
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这不是亲子关系。孩子只有一个父母(属于父母)。这是独立实体之间的多对多关系。这是一个重要的区别。
实际上,您无法按照现在的设计方式直接在 HQL 中从“父级”中删除“子级”。这是您的选择:
This is not a parent-child relation. Children have only one parent (the belong to the parent). This is a many-to-many relation between independent entities. This is a important difference.
You can't actually remove the "children" from the "parent" directly in HQL the way it is designed now. This are your options:
为了实现这一点,需要有某种从子实体开始的关系。
然后你可以简单地使用级联删除到它的3d(我猜这是一个多对多)表。
To make this happen, there needs to be a relationship of some sort, starting from the Child Entity.
Then you can simply use cascade-delete to its 3d (I'm guessing this is a many-to-many) table.