nHibernate逆映射
我有一个对象(对象 A),其中包含对象 B 的集合。我的映射类(流畅)设置完成了所有工作,问题是在尝试保存时。我想执行一次保存调用,然后还保存所有对象 B。同样,这有效,除非 nHibernate 在保存对象 A 后没有在对象 B 上分配外键变量。
我相信在这种情况下使用逆(?),但它似乎对我不起作用。对象 A 具有集合的映射:
HasMany(x => x.Responses)
.Inverse()
.KeyColumn("[ParentID]")
.Not.LazyLoad()
.Cascade.All()
.AsBag();
对象 B 具有对对象 A 的引用:
References(x => x.Entry, "[ParentID]")
.LazyLoad()
.Cascade.None();
我认为逆函数将位于对象 B 一侧,但引用不包含逆函数。
想法?
干杯
I have a single object (object A) which contains a collection of object B. I have my mapping classes (fluent) setup with this all the working, the problem is when trying to save. I want to perform a single save call and for this to then also save all object B's. Again, this works EXCEPT that nHibernate isn't assigning the foreign key variable on object B's after saving object A.
I believe inverse is used in such situations(?) but it doesn't appear to be working for me. Object A has the mapping for the collection:
HasMany(x => x.Responses)
.Inverse()
.KeyColumn("[ParentID]")
.Not.LazyLoad()
.Cascade.All()
.AsBag();
And object B has the reference to object A:
References(x => x.Entry, "[ParentID]")
.LazyLoad()
.Cascade.None();
I thought the Inverse would be on the object B side but References doesn't contain an Inverse function.
Thoughts?
Cheers
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为问题存在于将对象 B 添加到对象 A 的集合中。
看这里 http://eashi.wordpress.com/2008/08/ 22/nhibernate-inverse-attribute/
I think the problem exists in adding objects B to collection from object A.
Look here http://eashi.wordpress.com/2008/08/22/nhibernate-inverse-attribute/
我用来在父类上创建
AddChild
方法,如下所示:I use to create
AddChild
method on parent class like this: