Chapter 3. Querying an Entity Data Model

In the previous chapter, we showed you lots of different ways to model some fairly common database scenarios. In this chapter, we dive right into querying your models.

In these recipes we'll show you how to use LINQ and Entity SQL to query your models. We'll cover a wide range of common and some not so common scenarios that will help you understand some of the basics of querying your models.

Executing an SQL Statement

Problem

You want to execute an SQL statement.

Solution

Let's say you have a Payment table like the one shown in Figure 3-1 and you have created a model that looks like the one in Figure 3-2.

A Payment table that contains information about a payment made by a vendor

Figure 3.1. A ...

Get Entity Framework 4.0 Recipes: A Problem-Solution Approach now with the O’Reilly learning platform.

O’Reilly members experience live online training, plus books, videos, and digital content from nearly 200 publishers.