Say i have typical students and courses classes, pulled as entities and auto generated via EF6. Example
class Student {
string name,
virtual ICollection<Course> Courses
virtual ICollection<A> example a
virtual ICollection<B> example b
virtual ICollection<C> example c
etc...
}
class Course {
DateTime courseDate,
virtual Student Student
etc...
}
I want to be able to get a list of students who have a course tomorrow and just have that course in the child list. (Presume max 1 course per day)
Things i've tried....
List<Student> Method 1 (DateTime date)
{
ctx.Configurations.LazyLoadingEnabled = false;
return (from s in ctx.Students.Include(x=>x.Course)
join c in ctx.Courses
where c.courseDate == date
select s).ToList();
}
Result: List of students with course (but nothing in the courses object)
List<Student> Method 2 (DateTime date)
{
return ctx.Students.Where(x=>x.Courses.Any(y=>y.courseDate==date)).ToList()
}
Result: List of Students with all properties attached and unfiltered.
List<Student> Method 3 (DateTime date)
{
ctx.Configurations.LazyLoadingEnabled = false;
return ctx.Students.Include(x=>x.Courses).Where(x=>x.Courses.Any(y=>y.courseDate==date)).ToList()
}
Result: List of Students with just courses property attached but STILL unfiltered.
List<Student> Method 4 (DateTime date)
{
ctx.Configurations.LazyLoadingEnabled = false;
return
ctx.Students.Include(x=>x.Courses).Where(x=>x.Courses.Select(y=>y.courseDate).Contains(date)).ToList()
}
Result: Same as above
The List goes on....
I do not want the data to be pulled through and filtered after initial query.
Can anyone help.