NHibernate 3 lazy properties and impatient requests

I am using NHibernate 3.0.0, and the new features are lazy. However, in some queries, I want to look forward to loading properties, and I would like the query to result in entity instances without a proxy. I also prefer to use the LINQ provider or QueryOver. So my two questions are related to this:

  • I know that passionate loading of properties can be achieved in HQL with "fetching all properties", but can you do the same with LINQ Provider or QueryOver?
  • If I execute an HQL query with "fetch all properties", the objects are actually loaded as a result, but they are still proxied. Is there any way to avoid this?

Greetings

+7
source share
2 answers

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

I don’t remember at all how in the NH Google discussions I couldn’t find the thread. The answer will be updated if I can find it today. But as of the current 3.1 release, it is only in HQL.

To question 2 : I don’t know if there is a way to avoid this, I usually convert them to DTO and serialize DTO, not NH Poco, when using WCF. The Leonardo link looks interesting and may help.

+4
source

You can use this http://davybrion.com/blog/2009/03/must-everything-be-virtual-with-nhibernate/ to disable the lazy loading of your classes (without a proxy)
You can use this http://nhibernate.info/doc/nh/en/index.html#querycriteria-dynamicfetching to eagerly load your properties
Or you can try this http://www.timvasil.com/blog14/post/2008/02/WCF-serialization-with-NHibernate.aspx and still use the proxy.

0
source

All Articles