NHibernate, get a grandchildren team using QueryOver w / Future

I am trying to get all the collections (non-Cartesian product) of the parent object, but I cannot figure out how to get the grandchildren. The structure of the table is as follows:

enter image description here

The following code gets my parents and his collections Child1 and Child2, as well as his collection ParentChild3, but I don’t know how to structure the query to get the grandchildren of Child3 (and defer them to Future ()).

var parent = _session
    .QueryOver<Parent>()
    .Where(x => x.Id == id)
    .Future<User>();

var children1 =_session
    .QueryOver<Parent>()
    .Where(x => x.Id == id)
    .Fetch(x => x.Children1).Eager
    .Future<Parent>();

var children2 =_session
    .QueryOver<Parent>()
    .Where(x => x.Id == id)
    .Fetch(x => x.Children2).Eager
    .Future<Parent>();

var parentChildren3 =_session
    .QueryOver<Parent>()
    .Where(x => x.Id == id)
    .Fetch(x => x.ParentChildren3).Eager
    .Future<Parent>();

// how to get children3, now?

return parent.SingleOrDefault();

Semi-communication: is this the best way to get all the collections? Is it better (and possible) to use a query that gets the result using connections instead?

+5
source share
2 answers

How to get Children3:

ParentChildren alias = null;
var parentChildren3 =_session
    .QueryOver<Parent>()
    .Where(x => x.Id == id)
    .JoinAlias(x => x.ParentChildren3, () => alias)
    .Fetch(() => alias.Children3).Eager
    .Future<Parent>();

Half Link: This is the best way to find out.

ParentChild , . NHibernate , .

+2

:

var parentChildren3 =
        _session
            .QueryOver<Parent>()
            .Fetch(x => x.ParentChildren3).Eager
            .Fetch(x => x.ParentChildren3.First().Child3).Eager
            .Where(x => x.Id == id)
            .Future<Parent>();

: https://groups.google.com/forum/?fromgroups=#!topic/nhusers/ER5BvVnCT5Q

+2

All Articles