有人看到我在做什么错吗?ProjectActivityTasks
具有UnitOfMeasureId
和ProjectActivityTaskTypeId
。用它的编写方式,它认为UnitOfMeasure
转到ProjectActivityTaskType
。它在ThenInclude
上为UnitOfMeasure
说错了
ProjectActivityTaskType不包含UnitOfMeasure的定义
哪个是正确的。 UnitOfMeasure
转到ProjectActivityTasks
。
我正在引用此页面,但它似乎不能这样工作:https://docs.microsoft.com/en-us/ef/core/querying/related-data
var qry = await _projectActivityRepository.GetAll()
.Include(x => x.ProjectActivityVehicles)
.ThenInclude(x => x.Vehicle)
.Include(x => x.ProjectActivityTasks)
.ThenInclude(x => x.ProjectActivityTaskType)
.ThenInclude(x => x.UnitOfMeasure)
.Where(x => x.Id == Id && x.TenantId == (int)AbpSession.TenantId)
.FirstOrDefaultAsync();
最佳答案
您可以(并且应该)重复Include(x => x.ProjectActivityTasks)
部分:
var qry = await _projectActivityRepository.GetAll()
.Include(x => x.ProjectActivityVehicles)
.ThenInclude(x => x.Vehicle)
.Include(x => x.ProjectActivityTasks)
.ThenInclude(x => x.ProjectActivityTaskType)
.Include(x => x.ProjectActivityTasks)
.ThenInclude(x => x.UnitOfMeasure)
.Where(x => x.Id == Id && x.TenantId == (int)AbpSession.TenantId)
.FirstOrDefaultAsync();
关于c# - 然后,EFCore Linq将两个外键包含到同一表中,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/46506692/