views:

19

answers:

1

I have a many-to-many relationship:

Application -> Applications_Servers -> Server

This is set up in my Entity Data Model and all is well. My problem is that I'd like to eager-load the whole graph of Applications so that I have an IEnumerable<Applications>, each Application member populated with the Servers collection associated by the many-to-many relationship.

Normally this wouldn't be a problem, but according to my research there must be a navigation property between Application and Server. This is not the case for me because my Applications_Servers join table has more in it than just the two keys. Therefore, there is no navigation property directly between Application and Server, and this doesn't work:

    var apps = (from a in context.Application.Include("Server")
               select a).ToList();

I get an error saying there is no navigation property on Application called "Server", and that's correct, there is none.

How do I write the query to eager-load my Applications with their Servers in this case?

+3  A: 

Just use the existing navigation properties.

context
   .Application
   .Include("Applications_Servers")
   .Include("Applications_Servers.Server")

This should eager load all associated Applications_Servers and Server entities.

Daniel Brückner
THANKS!!! I saw a comment like this on a blog but it wasn't very clear.
Dave Swersky