NHibernate的获取无代理对象 [英] NHibernate Get objects without proxy

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

问题描述

我使用NHibernate(2.0.1.4)与NHibernate.Linq(1.0.0.4),摆脱数据库类型节点的对象。



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



我用下面的LINQ查询

  VAR mynodes =从session.Linq<节点,节点>()其中ancestorNodes.Contains(node.Id)选择节点).ToList()

anchestorNodes是标识的用于节点对象获取的列表。

当我有3个的ID,在ancestorNodes名单,结果的最后一个对象(mynodes)我从查询得到的类型nodeProxy的。



这怎么可能?
为什么总是最后一个对象?
我怎样才能解决这个问题?


解决方案

如果您的代理对象实现INhibernateProxy,你可以与NHibernate用下面的代码unproxy对象:

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

希望这有助于!


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.

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

I used the following linq query:

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

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

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?

解决方案

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

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

Hope this helps!

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

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