NHibernate 3惰性属性和热切查询 [英] NHibernate 3 lazy properties and eager queries

查看:67
本文介绍了NHibernate 3惰性属性和热切查询的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用NHibernate 3.0.0和新功能的惰性属性.但是,在某些查询中,我想热切地加载属性,并且希望该查询产生非代理实体实例.我也更喜欢使用LINQ提供程序或QueryOver.所以我与此有关的两个问题是:

I'm using NHibernate 3.0.0 and the new feature lazy properties. However, in some queries I want to eagerly load the properties and I would like the query to result in non-proxied entity instances. I also prefer to use the LINQ provider or QueryOver. So my two questions related to this are:

  1. 我知道急于加载 属性可以在HQL中实现 与获取所有属性",但 可以用 LINQ提供程序还是QueryOver?
  2. 如果我使用获取所有属性"执行HQL查询,则确实会急切加载结果中的实体,但仍会对其进行代理.有办法避免这种情况吗?
  1. I know that eager loading of properties can be achieved in HQL with "fetch all properties" but is it possible to do the same with the LINQ provider or QueryOver?
  2. If I execute an HQL query with "fetch all properties" the entities in the result are indeed eagerly loaded but they are still proxied. Is there a way of avoiding this?

欢呼

推荐答案

对于问题1 :答案是否定的,如

For question 1: The answer is no, 'fetch all properties' as described in http://ayende.com/blog/4377/nhibernate-new-feature-lazy-properties is currently only supported in HQL.

我确实记得在NH Google讨论区的某个地方看到过我找不到主题.如果我今天能找到答案,将更新答案.但是从当前的3.1版本开始,它仅在HQL中使用.

I do remember seeing in the NH Google Discussions somewhere, I'm unable to find the thread. Will update answer if I can find it today. But as of the current 3.1 release it's only in HQL.

对于问题2 :我不知道是否有避免这种情况的方法,在使用WCF时,我通常将其转换为DTO并序列化DTO,而不是NH Poco.莱昂纳多的链接看起来很有趣,也许可以帮上忙.

For question 2: I don't know if there is a way to avoid this, I usually transform them to DTO's and serialize the DTO, not the NH Poco, when using WCF. Leonardo's link looks interesting and may be able to help.

这篇关于NHibernate 3惰性属性和热切查询的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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