对于一个TestType我想包括导航道具Schoolclass和Subject。如何做一个包含多个ThenInclude导航道具
我可以做一个:
.Include(t => t.TestType)
.ThenInclude(x => x.Subject)
但不是:
.Include(t => t.TestType)
.ThenInclude(x => x.Subject)
.ThenInclude(x => x.Schoolclass)
因此我尝试了小动作和工作:
我包括TestType 2次...
var test = await context.Tests.Where(t => t.SchoolyearId == schoolyearId)
.Include(t => t.TestType)
.ThenInclude(x => x.Subject)
.Include(t => t.TestType)
.ThenInclude(x => x.Schoolclass)
.AsNoTracking()
.ToListAsync();
那是官方的做法还是有更好的?
UPDATE
public class TestType
{
public TestType()
{
Tests = new HashSet<Test>();
}
public int Id { get; set; }
public string Name { get; set; }
public int Weight { 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; }
}
什么是您的对象定义? –
对象定义?你到底什么意思?哪个对象? :-) – Pascal
您的对象的定义 –