Using MultiCriteria

We need to run several queries to display forms and web pages. For example, it's common to display search results one page at a time. This typically requires two queries. The first counts all the available results and the second fetches the data for only 10 or 20 results. MultiCriteria allows us to combine these two queries into a single database round trip, potentially speeding up our application. In this recipe, we'll show you how to use MultiCriteria to fetch a paged-result set of products.

Getting ready

Complete the Getting Ready instructions at the beginning of Chapter 4, Queries.

How to do it…

  1. Add a new folder named MultiCriteria to the QueryRecipes project.
  2. Add a new struct named PageOf to the folder:
     public struct PageOf<T> ...

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.