Eager loading with QueryOver
In this recipe, we'll show you how to use QueryOver queries to eager load the child collections of our query results.
Getting ready
Complete the Getting Ready instructions at the beginning of this chapter.
How to do it…
Create a new folder named
EagerLoadingWithQueryOverin the project.Add a new class named
Recipein the folder:using NH4CookbookHelpers.Queries; using NH4CookbookHelpers.Queries.Model; using NHibernate; using NHibernate.Transform; namespace QueryRecipes.EagerLoadingWithQueryOver { public class Recipe : QueryRecipe { protected override void Run(ISession session) { var book = session.QueryOver<Book>() .Fetch(x => x.Publisher).Eager .SingleOrDefault(); Show("Book:", book); var movies = session.QueryOver<Movie>() .Fetch(x => x.Actors).Eager .OrderBy(x => x.Name).Asc .TransformUsing( ...