i’m certain that i’m missing something really obvious here.
what I want to acheive is quite simple-
I’d like one query to load all Users without hydrating their Posts and Followers collections.
In another query, I do want to initialize these collections, using SubSelect.
using Fetch(..) in the second query would issue left joins, which I don’t want.
I can define those collections’ fetching strategies in the mappings like so (fluently):
.Not.LazyLoad()
.Fetch.Subselect()
which would cause the second query to run the way I want it to, but then I can’t turn off the .Not.LazyLoad() for the first query (i’ve tried .Fetch(u => u.Posts).Lazy but that doesn’t seem to do anything).
what am I missing?
I normally set
lazy=truein my mappings (Ayende wrote about it) cause I prefer to control the behaviors in my code.Doing so your associations will be hydrated only if you require them.
Will load all your users but won’t load their posts, unless you access an element of the collection:
If you want to load some users and their posts you can simply do something like this:
or:
As you might have noticed using Fetch Eager:
uses an outer join which you do not want.
The previous two examples will have a problem you’ve mentioned in your comment.
If you want to avoid cartesian products in your result with QueryOver you can use
.TransformUsing(Transformers.DistinctRootEntity):You can find lot more information here.