I'm using Entity framework 4.1 code first and Here is a simplified version of my domain classes:
public class Tour
{
public string TourName { get; set; }
public virtual List<Event> Events { get; set; }
}
public class Event
{
public string EventName { get; set; }
public virtual List<Participant> Participants { get; set; }
}
public class Participant
{
public string ParticipantName { get; set; }
}
and in the client application I use these classes:
public class EventItem
{
public string DisplayName { get; set; }
public IEnumerable<ParticipantItem> Tourists { get; set; }
}
public class ParticipantItem
{
public string Name { get; set; }
}
and the query:
var query = from tour in context.Tours
from evt in tr.Events
where tour.ApiKey == APIKey
select new EventItem
{
DisplayName = evt.EventName,
Tourists = from person in evt.Participants
select new ParticipantItem
{
Name = person.ParticipantName
}
};
return query.ToList();
It works with the exception that the inner query expression returns no data ( from person in evt.Participants
...). I think it has something to do with lazy loading of Participants property of the Event object. But how to use "Include" in this query if that is the issue?