On 02.02.2012 13:15, Boris Drajer wrote:
Hi,

Sorry if I misunderstand, but it seems to me that the crucial point
you're missing is that it's not enough to load the contents of the
collections, NHibernate needs to load the collection as a part of its
owner. If you retrieve individual objects, they will all be present in
the session but the collections that contain them will remain
uninitialized. When you access such collections, NHibernate executes a
query and then for each row retrieved discovers that it's already
cached in the session, so it only adds it to the collection. What you
need to do is to load them *together*. This is best illustrated with
HQL:

from A a left join fetch a.Bs where [something]

This loads the A's along with their collections of B's, not just A's
and B's separately.

With QueryOver, I think it would look something like this:

var q = session.QueryOver<A>().Fetch(a =>
a.Bs).Eager.Where([something]);

You can execute multiple different queries of this sort to load
different portions of the object graph.

Interesting! I was wondering the same myself recently, and this seems to be exactly what I need. Is there any information available how this can be done with the LINQ-provider? I guess, it's "just" a matter of putting the right nodes into the expression tree. I was looking at the reference on NHforge, but didn't see anything pertinent.



Best Regards, David

--
You received this message because you are subscribed to the Google Groups 
"nhusers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/nhusers?hl=en.

Reply via email to