alwayslearning alwayslearning - 3 years ago 141
C# Question

entity framework:selecting top level entity given condition on nested entity

I have an object hierarchy like this:

(DbSet<Student>) Students
-> (List<Semester>) Semesters
-> (List<Module> Modules
->(List<Exam>) Exams
-> (String) Result

How do i get all students who have a result which equals B

Answer Source
Context.Students.Where(student => student.Semesters.Any(semester => semester.Modules.Any(module => module.Exams.Any(exam => exam.Result == result)))));

That will get you students with any exam that is the result you want.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download