對於一個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
您的對象的定義 –