I'm doing a lambda select on EF4.1, including another related DBSet in my current statement.
return dbEntity.GameTypes.Include(a => a.Draws)
.Where(d => d.IsActive == true )
.ToList();
I've got two classes:
//simplified versions of the 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 only want 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 refer to a navigation property defined on the type. Use dottedpaths for reference navigation properties and the Select operator for collection navigation properties.
Is something like this possible or would I need to filter the result afterwards? I'd then also like to order the total result by the latest Draw.DrawDate. If anyone could show me the proper way I'd be trully gratefull.