有谁看到我做错了什么?
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();
答案 0 :(得分:7)
您可以(并且应该)重复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();