【问题标题】:EFCore Linq ThenInclude Two Foreign Keys To Same TableEFCore Linq ThenInclude 两个外键到同一个表
【发布时间】:2017-10-01 04:42:57
【问题描述】:

有人知道我做错了什么吗?
ProjectActivityTasksUnitOfMeasureIdProjectActivityTaskTypeId。按照它的编写方式,它认为UnitOfMeasure 转到ProjectActivityTaskTypeThenInclude for 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();

【问题讨论】:

    标签: c# asp.net-core linq-to-entities entity-framework-core


    【解决方案1】:

    您可以(并且应该)重复 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();
    

    【讨论】:

      猜你喜欢
      • 2015-12-18
      • 1970-01-01
      • 2015-12-30
      • 1970-01-01
      • 1970-01-01
      • 2019-11-20
      • 2019-12-23
      • 1970-01-01
      • 2012-07-02
      相关资源
      最近更新 更多