Database Reference
In-Depth Information
Following is the output of the code in Listing 3-25:
All Media sorted by type...
Title: Woodworkers' Favorite Tools [Article]
Title: Building a Cigar Chair [Article]
Title: Upholstering the Cigar Chair [Video]
Title: Applying Finish to the Cigar Chair [Video]
Title: Tour of My Woodworking Shop [Video]
Title: Photos of My Cigar Chair [Picture]
How It Works
When we use Table per Hierarchy inheritance, we leverage a column in the table to distinguish which derived type
represents any given row. This column, often referred to as the discriminator column, can't be mapped to a property
of the base entity. Because we don't have a property with the discriminator value, we need to create a variable to hold
comparable discriminator values so that we can do the sort. To do this, we use a LINQ let clause, which creates a
the mediatype variable. We use a conditional statement to assign an integer to this variable based on the type of the
media. For Articles, we assign the value 1. For Videos, we assign the value 2. We assign a value of 3 to anything else,
which will always be of type Picture because no other derived types remain.
3-12. Paging and Filtering
Problem
You want to create a query with a filter and paging.
Solution
Let's say that you have a Customer entity type in a model, as shown in Figure 3-13 .
Figure 3-13. A model with a Customer entity type
You have an application that displays customers based on a filter. Your company has many customers (perhaps
millions!), and to keep the user experience as responsive as possible, you want to show only a limited number of
customers on each page. To create a query that both filters the customers and returns a manageable set for each
results page in your application, follow the pattern in Listing 3-26.
 
Search WWH ::




Custom Search