2012/1/30 Brad Laney <[email protected]>:
> Hello.
>
> I am trying to avoid N+1 and cartesian product when I need to do deep
> eager loads. I want to do this for performance. It is an EAV type of a
> data structure.
>

Is the problem too many queries, or that you absolutely cannot have
more than one roundtrip to the database?

[...]

>
>                var r = s.QueryOver<NHMapTest1>()
>                    .Where(x => x.Id == id)
>                    .Future();
>
>                s.QueryOver<NHMapTest2>()
>                    .Where(x => x.Parent.Id == id)
>                    .Future();
> Running r.Single(); returns the entity, but if you do .Items it'll
> query the DB, even tho they were selected in the 2nd future. Both
> queries run correctly and return valid results.

When you access the collection, even though a number of objects of the
collection's member type has been loaded, NH doesn't know they are
part of the collection, that's why it needs to query again. Looking at
the child's Parent reference of loaded objects wouldn't be enough,
since it doesn't know if those are _all_ the children.

Have you set proper batch size on your collections and classes? And
possibly specify subselect fetching for the collections. With that you
should be able to rely on lazy fetch, but with a limited number of
round trips.


/Oskar

-- 
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