Make a ThenFetch for the QueryOver provider/syntax

Description

The LINQ provider has a ThenFetch method to eagerly load a table referenced by another table referenced by another table (so with A.B.C, B can be eagerly loaded through Fetch, C can be eagerly loaded through ThenFetch). The QueryOver provider doesn't have anything similar (at least if B is a "collection". Haven't tested with B being 0-1). You can go around the problem using something like:

B aliasB = null;
C aliasC = null;

query = query.JoinAlias(p => p.B, () => aliasB, JoinType.LeftOuterJoin)
.JoinAlias(() => B.C, () => aliasC, JoinType.LeftOuterJoin);

but the syntax is more complex and I'm not even sure it's equivalent (taken from http://stackoverflow.com/questions/4801235/nhibernate-3-alternatives-to-thenfetch-in-queryover )

Environment

None

Activity

Massimiliano Alberti December 20, 2011 at 4:15 PM

Yes perfectly... I didn't know. I thought that writing something like that would make everything go boom if B was empty for some B, but clearly it doesn't because the expression is parsed, not executed. Thanks a lot!

Richard Brown December 20, 2011 at 2:48 PM

https://github.com/nhibernate/nhibernate-core/blob/master/src/NHibernate.Test/Criteria/Lambda/QueryOverFixture.cs#L732

There is already syntax available for collection properties:

query
.Fetch(p => p.B)
.Fetch(p => p.B.C) // if B is not a collection ... or
.Fetch(p => p.B[0].C) // if B is a collection ... or
.Fetch(p => p.B.First().C) // if B is an IEnumerable (using .First() extension method)

Does that provide the functionality you were after?

Not an Issue

Details

Assignee

Reporter

Components

Affects versions

Priority

Who's Looking?

Open Who's Looking?
Created December 9, 2011 at 4:47 PM
Updated December 20, 2011 at 8:02 PM
Resolved December 20, 2011 at 8:02 PM
Who's Looking?