Fetch vs FetchMany in NHibernate Linq provider

LinqNhibernateFetchEager Loading

Linq Problem Overview


NHibernate eager loading can be done using Fetch and FetchMany, as described in NHibernate Linq Eager Fetching on Mike Hadlow's blog.

What is the difference between these two methods and under what circumstance would each be used?

Linq Solutions


Solution 1 - Linq

Fetch should be used for references and FetchMany for collections.

This is particularly important because only FetchMany can be combined with ThenFetchMany to fetch "grandchildren" collections.

Example:

session.Query<User>()
       .FetchMany(u => u.Orders)
       .ThenFetchMany(o => o.OrderItems)

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionSimonView Question on Stackoverflow
Solution 1 - LinqDiego MijelshonView Answer on Stackoverflow