2017-09-30 95 views
2

有沒有人看到我在做什麼錯了?
ProjectActivityTasks具有UnitOfMeasureIdProjectActivityTaskTypeId。隨着它的寫法,它認爲UnitOfMeasureProjectActivityTaskType。它示數出來就ThenIncludeUnitOfMeasureEFCore Linq Then然後包括兩個外鍵到同一個表

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(); 

回答

5

你可以(也應該)重複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(); 
相關問題