Eager loading in EF1.0
- by Dave Swersky
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?