0
使用.NET Entity Framework 6我需要篩選包含的虛擬集合的元素。我的意思是很容易用下面的代碼解釋:實體框架篩選器lambda導航屬性
context.MyEntity.Include(navigationPropertyCollection => navigationPropertyCollection.Where(np => np.IsActive()))
代碼代碼僅僅是一個例子,從myEntity所想只包括navigationPropertyCollection的積極分子說。
有沒有一種明智的方法來做到這一點?
Thancks Eldho的回答,你當然作品的解決辦法,但使用匿名類型要更改的域和這不是非常明智的原因,而是需要將所有對象都投射到正確的域。 – Zeta
@Zeta你可以直接投影到你的viewmodel而不是匿名投影。嘗試這種 '選擇(p值=>新YourModel {ParentItems = P,ChildItems = p.ChildItems})ToList();' https://documentation.devexpress.com/#WPF/CustomDocument17979 – Eldho
使用謂詞在'.Select()'函數中生成的sql代碼會影響所有childItem的過濾,就像我需要的那樣。以下我在根問題中的示例代碼將是:'context.MyEntity.Include(myentity => myentity.navigationPropertyCollection).Select(myentity => myentity.navigationPropertyCollection.Where(n => m.IsActive())); ' – Zeta