EF Core 8 : getting grand children from grandparent

25 Views Asked by At

I am writing a an application which contains model classes with the following navigation properties

TestReport => Students => ClassSchedule => Tests

The relationship is one-to-many towards right side of every entity. I am using EF Core 8.0.

The TestReports is a master table whose details are in the ReportDetails table. I shall fetch the student's tests from the Tests table and store their grades in the ReportDetails table.

I want to get a list of Tests provided with the TestReportId.

What I am trying to do is get StudentId from TestReports and then get all the tests of that student from Tests table.

1

There are 1 best solutions below

0
Svyatoslav Danyliv On

Not enough information, but query should be something like this:

var query = 
    from r in context.TestReports
    from st in r.Students
    from t in st.ClassSchedule.Tests
    where t.Id == reportId
    select t;