Database Reference
In-Depth Information
Solution
Suppose you have a conceptual model like the one in Figure 5-20 . Each course has several sections. Each section is
taught by an instructor and has several students.
Figure 5-20. A model with a few related entities
To retrieve all of the courses, sections, instructors, and students represented in the database in a single query,
use the Include() method with a query path parameter, as shown in Listing 5-12.
Listing 5-12. Retrieving an Entire Object Graph in a Single Query
using (var context = new EFRecipesEntities())
{
var course = new Course { Title = "Biology 101" };
var fred = new Instructor { Name = "Fred Jones" };
var julia = new Instructor { Name = "Julia Canfield" };
var section1 = new Section { Course = course, Instructor = fred };
var section2 = new Section { Course = course, Instructor = julia };
 
Search WWH ::




Custom Search