My class relationship: ClassMaster 1----* ClassSessions
My Goal: Return all ClassMasters that have ClassSessions with StartDateTime greater than the current date, along with these ClassSessions (filtered by date).
In T-SQL I'd do this:
select *
from ClassSession
join ClassMaster on ClassMaster.ClassId = ClassSession.ClassId
Where ClassSession.StartDateTime > getdate()
I need to realize the same results in an Entity Framework 4 query. This is what I thought it would work, but does not:
var classes = ctx.ClassSessions
.Include("ClassMasters")
.Where(s => s.StartDateTime > DateTime.Now)
.Select(s => s.ClassMaster)
.ToList();
This give's me all the ClassMasters that have some ClassSession with StartDateTime > current date, but the ClassSessions property comes filled with all ClassSessions, including older than current date. I only want ClassSessions with StartDateTime > current date.
What am I doing wrong?
Thank you very much!