Lets say you have the following entity realtionship
School ||---|< Course >|--|< Student
Worst drawing ever, but a school can have several courses, and a course can have several students.
In EF I would normally do it like this to get all the data:
return _db.School
.Include(t => t.Classes)
.ThenInclude(c => c.Course)
.ThenInclude(s => s.Student)
But let say I only want students with name Billy. Then I would guess I could to it like this
return _db.School
.Include(t => t.Classes)
.ThenInclude(o => o.Course)
.ThenInclude(o => o.Student.Where(s => s.Studen.name.Equals( "Billy"))
Not possible as far as I can see, so therefore I do it like this:
return _db.School
.Select(school => new School()
{
Id = school.Id
Name = school.Name
Courses = school.Courses.Select(courses => new Course()
{
Id = course.Id,
Name = course.Name
Students = course.Students.Select(student => new Student()
{
Id = student.Id,
Name = student.Name
}).Where(s => s.Name.Equals("Billy"));
})
});
etc....
There must be a better way? Any suggestions?
The code is just mocked, so might be a bunch of syntax errors and typos. But you get the idea.