I\'m well aware this is an issue with a clear solution in more simple situations, but i have implemented something that i think doing it otherwise or changing it completely due
Include
never works if you project to an (anonymous or named) type. Think of it, in which class should EF include the child collection?
The include will work if you do
var query = from mission in context.Missions.Include("AssignedAgents")
join client in context.Clients on mission.ClientId equals client.Id
select mission
Then EF will have Mission
objects for which it can load AssignedAgents
collections.
If you don't want to get the full objects you can get the same effect by incorporating AssignedAgents
as a property in the anonymous type:
var query = from mission in context.Missions
join client in context.Clients on mission.ClientId equals client.Id
select new
{
mission,
client.Name,
client.Office,
client.Id,
Agents = mission.AssignedAgents
};