如何通过 Fluent NHibernate 从会话中级联逐出对象
我有一个嵌套对象(带有子对象的对象),我想从与一个数据库中的活动会话关联的存储库中检索该对象,将其逐出,并将其保存在另一个数据库中(不同的会话、不同的连接字符串、不同的存储库) )。我已经尝试过:
myISession.Evict(myObjectInstance);
我的 MappingConfiguration 适用
Conventions.Add(DefaultCascade.All())
于所有类型。
但我仍然收到“NHibernate.HibernateException:非法尝试将集合与两个打开的会话关联”。如何删除与原始会话的关联?
I've got a nested object (object with subobjects) that I'd like to retrieve from a repository associated with an active session from one database, evict it, and save it in another database (different session, different connection string, different repository). I have tried:
myISession.Evict(myObjectInstance);
My MappingConfiguration has
Conventions.Add(DefaultCascade.All())
for all types.
But I still get "NHibernate.HibernateException: Illegal attempt to associate a collection with two open sessions". How can I remove the association with the original session?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好的,事实证明我的对象,在本例中 myObjectInstance 由来自两个不同会话的对象组成,我们称它们为 A 和 B。 myObjectInstance 具有来自会话 A 的属性 myProp1 和来自会话 B 的 myProp2 属性。然后我要存储整个 myObjectInstance 中
不幸的是,我试图从会话 A
逐出 myObjectInstance,而不仅仅是 myProp1。解决方案是:
OK, it turns out my object, in this case myObjectInstance was composed of objects from two different sessions, let's call them A and B. myObjectInstance had properties myProp1 from session A, and myProp2 from session B. I was then to store the whole myObjectInstance in session B.
Unfortunately I was trying to evict myObjectInstance from session A, rather than just myProp1.
The solution was to: