如何通过 Fluent NHibernate 从会话中级联逐出对象

发布于 2024-10-22 04:28:38 字数 359 浏览 0 评论 0原文

我有一个嵌套对象(带有子对象的对象),我想从与一个数据库中的活动会话关联的存储库中检索该对象,将其逐出,并将其保存在另一个数据库中(不同的会话、不同的连接字符串、不同的存储库) )。我已经尝试过:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

∞琼窗梦回ˉ 2024-10-29 04:28:38

好的,事实证明我的对象,在本例中 myObjectInstance 由来自两个不同会话的对象组成,我们称它们为 A 和 B。 myObjectInstance 具有来自会话 A 的属性 myProp1 和来自会话 B 的 myProp2 属性。然后我要存储整个 myObjectInstance 中

不幸的是,我试图从会话 A

逐出 myObjectInstance,而不仅仅是 myProp1。解决方案是:

NHibernateUtil.Initialize(myObjectInstance.myProp1); //eager load object being evicted.
_dataSession.Evict(myObjectInstance.myProp1);
MyObjectRepository.Save(myObjectInstance);

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:

NHibernateUtil.Initialize(myObjectInstance.myProp1); //eager load object being evicted.
_dataSession.Evict(myObjectInstance.myProp1);
MyObjectRepository.Save(myObjectInstance);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文