Using Futures
We've learned to use MultiCriteria and MultiQuery to batch our queries together. NHibernate's Futures feature provides a simpler API for batching criteria and queries. In this recipe, we'll show you how to use NHibernate's new Futures feature to return a paged product result. Both LINQ and HQL are used in the same method, to show the syntactic difference but also that they can work together.
Getting ready
Complete the Getting Ready instructions at the beginning of Chapter 4, Queries.
How to do it...
Add a new folder named
Futures
to theQueryRecipes
project.Add a new
struct
namedPageOf
to the folder:using System.Collections.Generic; namespace QueryRecipes.Futures { public struct PageOf<T> { public int PageCount; public int PageNumber; public IEnumerable<T> PageOfResults; } }
Add a new class named
Queries
to the folder:using System; using System.Linq; using NH4CookbookHelpers.Queries.Model; using NHibernate; using NHibernate.Linq...