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...

  1. Add a new folder named Futures to the QueryRecipes project.
  2. Add a new struct named PageOf to the folder:
    using System.Collections.Generic; namespace QueryRecipes.Futures { public struct PageOf<T> { public int PageCount; public int PageNumber; ...

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.