Getting detail objects on a master->detail->detail query in Microsoft Entity Framework

This one had me banging my head for the last couple of hours…  I have Entity A, B, and C in my Entity Diagram with A linking to B and B linking to C.  I want to find all of the C items that are associated with a specific instance of A.  Running through a range of ways to solve the issue got me no where, other than frustrated.  Fortunately, I found the answer on StackOverflow.com with this article.  Long and short of it is that one has to do a .Include statement in the LINQ query on the table to include everything needed.  So, the code would look like this:

var foo = from tempA in A.Include(“Bs.Cs”)

where tempA.Id = 1234

select tempA;

At that point, all of the B and C child objects are loaded.

I’ll just shake my head and refrain from commenting….

 

Advertisements