问题描述
有人看到我在做什么错吗?ProjectActivityTasks
具有UnitOfMeasureId
和ProjectActivityTaskTypeId
.通过编写方式,它认为UnitOfMeasure
转到ProjectActivityTaskType
.在ThenInclude
上错误地表示UnitOfMeasure
的说法
Does anyone see what I am doing wrong?ProjectActivityTasks
has the UnitOfMeasureId
and the ProjectActivityTaskTypeId
. With the way it is written, it thinks that UnitOfMeasure
goes to ProjectActivityTaskType
. It is erroring out on the ThenInclude
for UnitOfMeasure
saying
这是正确的. UnitOfMeasure
转到ProjectActivityTasks
.
which is correct. UnitOfMeasure
goes to ProjectActivityTasks
.
我正在引用此页面,但它似乎无法以这种方式工作: https://docs.microsoft.com/en-us/ef/core/querying/related-data
I was referencing this page but it does not seem to work this way: 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)
部分:
You can (and should) repeat the Include(x => x.ProjectActivityTasks)
part:
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();
这篇关于然后,EFCore Linq将两个外键包含到同一表中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!