Eager loading in EF1.0

Posted by Dave Swersky on Stack Overflow See other posts from Stack Overflow or by Dave Swersky
Published on 2010-05-14T18:21:18Z Indexed on 2010/05/14 18:24 UTC
Read the original article Hit count: 219

Filed under:
|

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?

© Stack Overflow or respective owner

Related posts about entity-framework

Related posts about LINQ