還是 LINQ 的新手,所以要友好。
這個查詢:
var query = _ODSContext.AllFacilities
.Where(f => f.AllFacilityContacts.Any(c => ProviderContactIds.Contains(c.ContactID) &&
(c.ContactTypeName == "Primary Rep")))
.Where(f => f.TermDate > DateTime.Now)
.Include(a => a.Address)
.Include(b => b.AllFacilityContacts)
.Include(c => c.AllPractitionerLocations)
.Include(e => e.AllFacilityServices)
.OrderBy(f => f.FacilityName);
作業正常。
但是,我想添加一個連接到 AllpractitionerLocations 的表:
這是我嘗試過的:
var query = _ODSContext.AllFacilities
.Where(f => f.AllFacilityContacts.Any(c => ProviderContactIds.Contains(c.ContactID) &&
(c.ContactTypeName == "Primary Rep")))
.Where(f => f.TermDate > DateTime.Now)
.Include(a => a.Address)
.Include(b => b.AllFacilityContacts)
.Include(c => c.AllPractitionerLocations)
.Include(d => d.AllPractitionerNetworkSpecialty)
.Include(e => e.AllFacilityServices)
.OrderBy(f => f.FacilityName);
但我得到:
'AllFacility' does not contain a definition for
'AllPractitionerNetworkSpecialties' and no accessible extension method
'AllPractitionerNetworkSpecialties' accepting a first argument of type
'AllFacility' could be found (are you missing a using directive or an assembly reference?
這在技術上是準確的。AllPractitionerNetworkSpecialties 與 AllPractitionerLocations 相關。
如何在 LINQ 中連接這兩個表?
謝謝,
uj5u.com熱心網友回復:
你使用 ThenInclude
簡單地說,Include從根物體開始,從ThenInclude您呼叫它的物體型別開始。如果您將圖形視為以 AllFacilities 作為中心的中心輻射型事務,則 Include 將從中心啟動另一個輻射,而 ThenInclude 繼續現有輻射。如果客戶有訂單并且訂單有產品,您將context.Customer.Include(... Orders).ThenInclude(... Products). 如果您想“回傳中心”并獲得 Customer>Address>Country>TaxYearCodings,您會
context.Customer
.Include(... Orders)
.ThenInclude(... Products)
.Include(... Address)
.ThenInclude(... Country)
.ThenInclude(... TaxYearCodings)
當我們用 ThenInclude 表示“繼續一個分支”時,我們傾向于縮進另一個級別,并且將所有 Includes 縮進相同的表示“回到集線器”
當心; 開始時加載的資料量(然后)包括很多可能是巨大的
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/318190.html
上一篇:我可以按(LINQ)分組并添加一個欄位并連接另一個欄位嗎?
下一篇:C#中的“列舉物件”是什么意思?
