NHibernate 在没有代理的情况下获取对象 [英] NHibernate Get objects without proxy

查看:35
本文介绍了NHibernate 在没有代理的情况下获取对象的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 NHibernate(2.0.1.4) 和 NHibernate.Linq(1.0.0.4) 从数据库中获取节点类型的对象.

I am using NHibernate(2.0.1.4) with NHibernate.Linq(1.0.0.4) to get Objects of the type Node from the Database.

当我得到这些对象时,我得到的集合的最后一个对象是 Proxy 类型(因为我使用了 "NHibernate.ByteCode.LinFu"" )

When I get these objects, the last object of the collection I got is of the type Proxy (because I used "NHibernate.ByteCode.LinFu"" )

我使用了以下 linq 查询:

I used the following linq query:

var mynodes = from node in session.Linq<Node>() where ancestorNodes.Contains(node.Id) select node).ToList()

anchestorNodes 是要获取的节点对象的 Id 列表.

anchestorNodes is a list of Id's for the node objects to get.

当我在ancestorNodes"列表中有 3 个 id 时,我从查询中得到的结果的最后一个对象 (mynodes) 是 nodeProxy 类型.

When I have 3 id's in the "ancestorNodes" list, the last object of the result (mynodes) I got from the query is of the type nodeProxy.

怎么会这样?为什么它总是最后一个对象?我该如何解决这个问题?

How could this be? Why is it always the last object? How can I solve this problem?

推荐答案

如果您的 Proxy 对象实现了 INhibernateProxy,您可以使用以下代码使用 NHibernate 取消代理对象:

If your Proxy object implements INhibernateProxy, you can unproxy the object with NHibernate with the following code:

iAmaSession.GetSessionImplementation().PersistenceContext.Unproxy(iAmaProxy)

希望这有帮助!

这篇关于NHibernate 在没有代理的情况下获取对象的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆