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…
Add a new folder named
MultiCriteria
to theQueryRecipes
project.Add a new
struct
namedPageOf
to the folder: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.Collections.Generic; using System.Linq; using...