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…

  1. Add a new folder named MultiQueries to the QueryRecipes project.
  2. Add a new struct named PageOf to the folder:
     public ...

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.