NHibernate 是否可以流畅地配置为在子项引用设置为 null 时删除子项?
我听说这也可以通过触发器来完成,但如果可以的话我宁愿不走那条路。现在看来,清空对子对象的引用只会使它们在数据库中成为孤立对象,至少可以说这并不理想。
谢谢!
I've heard this can also be accomplished with triggers, but I'd rather not go that road if I can. Right now it seems like nulling references to child objects just leaves them orphaned in the database, which isn't ideal to say the least.
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以设置级联选项来删除孤立对象:
要实现此操作,您需要从父对象集合中删除子对象并刷新会话:
You can set the cascade option to delete orphans:
To make this work you need to remove the child object from the parent's collection and flush the session:
我这里没有 Fluent.NH,但我知道您可以指定映射的级联类型。将其设置为 all-delete-orphan 应该可以满足您的要求。
如果您使用基于约定的配置,这应该为您提供一个起点。
级联保存流畅的 NHibernate 自动映射
I don't have Fluent.NH here but I know you can specify the cascade type for a mapping. Setting it to all-delete-orphan should do what you're asking.
If you're using convention based configuration this should give you a starting point..
Cascade Saves with Fluent NHibernate AutoMapping