2017-04-10 41 views
3

我已閱讀了有關如何在EF內核中包含所有屬性的一些主題。 我有這樣的事情:EF每次加入兒童時都會加入表格

_dbcontext.Transaction 
.Include(x => x.Enterprise).ThenInclude(x => x.Manager) 
.Include(x => x.Enterprise).ThenInclude(x=> x.Address) 
.Include(x => x.Enterprise).ThenInclude(x=> x.Example) 
... 

每次包括企業單位,的EntityFramework創建一個新的左聯接行。導致這樣的事情:

SELECT TOP(1) x.Id, x.OtherColumnNames... 
FROM Transaction as x 
LEFT JOIN Enterprise AS e1 on x.EnterpriseId = e1.Id 
LEFT JOIN Enterprise AS e2 on x.EnterpriseId = e2.Id 
LEFT JOIN Manager AS m1 on e2.ManagerId = m1.Id 
LEFT JOIN Enterprise AS e3 on x.EnterpriseId = e3.Id 
LEFT JOIN Address AS a1 on e3.AddressId= a1.Id 
LEFT JOIN Enterprise AS e4 on x.EnterpriseId = e4.Id 
LEFT JOIN Example AS e1 on e4.ExampleId= e1.Id 
... 

上我怎樣才能使EF只剩下加入我的企業表一旦有什麼建議?因爲這不是完成數據庫調用的好方法,而且會降低整個查詢速度。

回答

2

JOIN重複是一個已知的EF核心問題。不幸的是,它在EF Core 1.1中沒有修復。根據this thread,問題被分配到2.0.0里程碑,沒有任何預計發佈日期。