Database Reference
In-Depth Information
Chapter 3
Querying an Entity Data Model
In the previous chapter, we showed you many ways to model some fairly common database scenarios. The recipes in
this chapter will show you how to query your model. Generally speaking, you can query your model three different
ways, using:
1.
LINQ to Entities
2.
Entity SQL
3.
Native SQL
We'll demonstrate all three approaches in this chapter and, at the same time, cover a wide range of common, and
not so common, scenarios that will help you understand the basics of querying models with Entity Framework. We'll
also explore some of the new capabilities for querying data available with Entity Framework 6.
3-1. Querying Asynchronously
You have a long-running Entity Framework querying operation. You do not want to block the application running on
the main thread while the query executes. Instead, you'd like the user to be able to perform other operations until
data is returned. Equally important, you will want to query the model leveraging the Microsoft LINQ-to-Entities
framework, which is the preferred approach for querying an entity data model.
Solution
Let's say that you have a model like the one shown in Figure 3-1 .
Figure 3-1. A model with an Associate entity type representing an associate; and an AssociateSalary entity type
representing the salary history for the associate
 
Search WWH ::




Custom Search