在 NHibernate 中将双向多对多关系的哪一侧设置为逆关系重要吗?
简单的问题:在 NHibernate 中将双向多对多关系的哪一侧设置为逆关系重要吗?如果是这样,将其设置在一端与另一端有何影响?
更多澄清:我正在设置关系的双方:
Parent.Children.Add(child);
Child.Parents.Add(parent);
在这样的情况下,我将哪一方标记为反向有关系吗?
Simple question: does it matter which side of a bidirectional many-to-many relationship you set as the inverse in NHibernate? And if so, what are the implications of setting it on one end vs. the other?
Some more clarification: I'm setting both sides of the relationship:
Parent.Children.Add(child);
Child.Parents.Add(parent);
In a case like this, does it matter which side I mark as inverse?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
是的,这很重要,仅对关联的反向端所做的更改不会持久。
您可以查看 nhibernate 文档以获取更多详细信息。这里有链接:
http://www.nhforge.org/doc /nh/en/#collections-bidirection
编辑
我的答案不会随着您的添加而改变,但我会尽力解释得更好:-)
如果您将 Parent.Children 设置为
inverse = true
您需要保存 Child 对象才能保存关系。如果您只保存Parent,那么如果您使用inverse = true
设置Child.Parent,则关系将不会被保存,您需要保存Parent对象才能保存关系。如果您仅保存子级,则不会保存该关系
Yes it matters, changes made only to the inverse end of the association are not persisted
You may check nhibernate documentation for further details. Here you have the link:
http://www.nhforge.org/doc/nh/en/#collections-bidirectional
EDIT
My answer doesn't change with your addition, but I'll try to explain it better :-)
if you set Parent.Children with
inverse = true
you need to save Child object in order to save the relation. If you ONLY save Parent then the relation won't be savedif you set Child.Parent with
inverse = true
you need to save Parent object in order to save the relation. If you ONLY save Child then the relation won't be saved