Database Reference
In-Depth Information
Figure 5-21. A model for Plumbers with their JobSite and other related entities
In this model, the Plumber entity extends the Tradesman entity. A Plumber has a JobSite that is represented by
a one-to-many association. The JobSite type extends the Location entity. Location has a Phone, which is represented
by a one-to-many association. Finally, a JobSite can have zero or more Foremen. A one-to-many association also
represents this.
Suppose that you want to retrieve a plumber, the job site she works on, the job site's phone number, and all of the
foremen at the job site. You want to retrieve all of this in one round trip to the database.
The code in Listing 5-13 illustrates one way to use the Include() method to eagerly load the related entities in
one query.
Listing 5-13. Retrieving Related Entities in One Round Rrip to the Database Using Eager Loading with the
Include() Method
using (var context = new EFRecipesEntities())
{
var foreman1 = new Foreman { Name = "Carl Ramsey" };
var foreman2 = new Foreman { Name = "Nancy Ortega" };
var phone = new Phone { Number = "817 867-5309" };
 
Search WWH ::




Custom Search