Using MultiQuery
Similar to how we can combine several ICriteria and QueryOver queries into a single database round trip with MultiCriteria, we can combine several HQL and/or SQL queries with MultiQuery. Particularly in a production setting, where the database and application are on separate machines, each round trip to the database is very expensive. Combining work in this way can greatly improve application performance. In this recipe, we'll show you how to fetch a product count and page of product results using a MultiQuery.
Getting ready
Complete the Getting Ready instructions at the beginning of Chapter 4, Queries.
How to do it…
Add a new folder named
MultiQueriesto theQueryRecipesproject.Add a new
structnamedPageOfto the folder:public struct PageOf<T> { public int PageCount; public int PageNumber; public IEnumerable<T> PageOfResults; }Add a new class named
Queriesto the folder:using System; using System.Collections.Generic; using System...