Alex Rivera | Logout

Eager loading child collection with NHibernate

Asked 2009-06-02T00:11:21.073
25

I want to load root entities and eager load all it's child collection and aggregate members.

Have been trying to use the SetFetchMode in FluentNHibernate, but I am getting duplicates in one of the child collection since I have a depth of 3 levels. DistinctRootEntityResultTransformer unfortunately only removes the root duplications.

return Session.CreateInvoiceBaseCriteria(query, archived)
    .AddOrder(new Order(query.Order, query.OrderType == OrderType.ASC))
    .SetFetchMode("States", FetchMode.Eager)
    .SetFetchMode("Attestations", FetchMode.Eager)
    .SetFetchMode("AttestationRequests", FetchMode.Eager)
    .SetFetchMode("AttestationRequests.Reminders", FetchMode.Eager)
    .SetResultTransformer(new DistinctRootEntityResultTransformer())
    .List<Invoice>();

Could I use multi queries or something similar to archive this?

Furthermore, wouldn't this approach result in unnecessarily huge result sets from the database?

Any suggestions?

Edit
Report

1 Answer

0

While it might not be exactly what you are looking for, I would recommend looking at this article:

Eager loading aggregate with many child collections

If you look around the rest of that site you will find even more posts that discuss eager loading and other great nHibernate stuff.

answered 2009-06-02T08:39:19.337

Your Answer