<分区>
1 个测试分配了 1 个测试类型。
我需要加载与测试相关的所有 TestType 实体或不加载 Schoolclass 、 Subject 和 Assigned Pupils 到测试(PupilsTests)
.SelectMany 或 .Select 在运行时在这里失败。
我尝试了 Include 和 ThenInclude 的不同组合,但没有机会通过 PupilsTests 获得测试。
当我使用 context.Tests
但这会导致我只得到分配给测试的测试类型 - innerjoin - 但我需要所有 TestTypes 及其测试和他们的 PupilsTests,我希望它在一个查询中。
var testtypes = await context.TestTypes
.Include(x => x.Schoolclass)
.Include(x => x.Subject)
.Include(x => x.Tests.SelectMany(z => z.PupilsTests))
.Where(t => t.SchoolyearId == schoolyearId)
.AsNotTracking()
.ToListAsync();
public class TestType
{
public TestType()
{
Tests = new HashSet<Test>();
}
// Props removed for clarity
public int Id { get; set; }
public ISet<Test> Tests { get; set; }
public Schoolyear Schoolyear { get; set; }
public Schoolclass Schoolclass { get; set; }
public Subject Subject { get; set; }
public int SchoolyearId { get; set; }
}
public class Test
{
public Test()
{
PupilsTests = new HashSet<PupilTest>();
}
// Props removed for clarity
public int Id { get; set; }
public ISet<PupilTest> PupilsTests { get; set; }
public TestType TestType { get; set; }
}