gpt4 book ai didi

c# - 无法通过一个查询使用 Include 或 ThenInclude 或 Select/Many 加载相关数据

转载 作者:行者123 更新时间:2023-11-30 20:32:37 25 4
gpt4 key购买 nike

<分区>

1 个测试分配了 1 个测试类型。

我需要加载与测试相关的所有 TestType 实体或不加载 Schoolclass 、 Subject 和 Assigned Pupils 到测试(PupilsTests)

.SelectMany 或 .Select 在运行时在这里失败。

我尝试了 Include 和 ThenInclude 的不同组合,但没有机会通过 PupilsTests 获得测试。

当我使用 context.Tests

开始查询时,我只能获得带有测试的 PupilsTests

但这会导致我只得到分配给测试的测试类型 - 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; }


}

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com