有人看到我在做什么错吗?
ProjectActivityTasks具有UnitOfMeasureIdProjectActivityTaskTypeId。用它的编写方式,它认为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/

10-10 10:24