Database Reference
In-Depth Information
// Strongly typed query path argument for the Include method
using (var context = new EFRecipesEntities())
{
var graph = context.Courses
.Include(x => x.Sections.Select(y => y.Instructor))
.Include(x => x.Sections.Select(z => z.Students));
Console.WriteLine("Courses");
Console.WriteLine("=======");
var result = graph.ToList();
foreach (var course in graph)
{
Console.WriteLine("{0}", course.Title);
foreach (var section in course.Sections)
{
Console.WriteLine("\tSection: {0}, Instrutor: {1}", section.SectionId,
section.Instructor.Name);
Console.WriteLine("\tStudents:");
foreach (var student in section.Students)
{
Console.WriteLine("\t\t{0}", student.Name);
}
Console.WriteLine("\n");
}
}
}
Console.WriteLine("Press <enter> to continue...");
Console.ReadLine();
}
The code in Listing 5-12 produces the following output:
Courses
Courses
=======
Biology 101
Section: 19, Instructor: Fred Jones
Students:
Jim Roberts
Susan O'Reilly
Section: 20, Instructor: Julia Canfield
Students:
Jerry Jones
Cathy Ryan
Search WWH ::




Custom Search