I am making a lambda selection on EF4.1, including another related DBSet in my current application.
return dbEntity.GameTypes.Include(a => a.Draws)
.Where(d => d.IsActive == true )
.ToList();
I have two classes:
public class GameType
{
public Nullable<bool> IsActive { get; set; }
public virtual ICollection<Draw> Draws { get; set; }
}
public class Draw
{
public int DrawID { get; set; }
public int GameTypeID { get; set; }
public System.DateTime DrawDate { get; set; }
}
But I want only the next upcoming draw for each GameType. Essentially, I want to do something like
return dbEntity.GameTypes.Include(a => a.Draws.Where(aw => aw.DrawDate > System.DateTime.Now)
.OrderBy(ao => ao.DrawDate)
.First())
.Where(d => d.IsActive == true )
.ToList();
But it gives me:
The Include path expression must specify the navigation property defined in the type. Use dottedpath for reference navigation properties and the Select statement for collection navigation properties.
Is something like this possible or will I need to filter the result afterwards? I would also like to order the overall result from the latest version of Draw.DrawDate. If someone could show me the right path, I would love to work.