Eager loading child collections
Often, when we query for some set of entities, we also need to load a few children of those entities. In the Eager loading with… recipe, in the previous chapter, we learned how to use different fetch
syntaxes to eager load referenced entities and collection. We concluded that there are a few scenarios where the standard methods don't work as desired. In this recipe, we'll show you how to use subqueries and/or NHibernate's Futures, together with the session cache, to overcome these issues.
Getting ready
Complete the Getting Ready instructions at the beginning of Chapter 4, Queries.
How to do it...
- Add a new folder named
AdvancedEagerLoading
to theQueryRecipes
project. - Add a new class named
Recipe
to the folder:using ...
Get NHibernate 4.x Cookbook - Second Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.