![](/img/trans.png)
[英]IncludeFilter in EntityFramework CORE-Plus not filtering the included record
[英]Filtering On ThenInclude, with EntityFrameworkPlus IncludeFilter
我正在嘗試向下過濾三個子級別,並僅找到 PropertyMailingAddress.Status== True 的子元素。
如何將過濾器向下轉換三個級別並使用 EntityFrameworkPlus IncludeFilter 進行嵌套過濾? 最有效的方法是什么?
Class 結構嵌套如下:
這種原始方式不起作用:
var result = await db.Property.Include(pm => pm.PropertyParty)
.Include(pm => pm.PropertyParty)
.ThenInclude(x => x.Party)
.ThenInclude(x => x.PartyMailingAddress)
.ThenInclude(x => x.PropertyMailingAddress)
.Where(a => a.PropertyParty.Any(x => (x.Party.PartyMailingAddress.Any(z => z.PropertyMailingAddress.Any(h => h.Status == true))))).ToListAsync();
嘗試使用 Entity Framework Plus 的有效方法:最后一行是否必須重新鏈接並再次與上面的嵌套 wheres 連接,或者是否可以?
var result = await db.Property.Include(pm => pm.PropertyParty)
.Include(pm => pm.PropertyParty)
.ThenInclude(x => x.Party)
.ThenInclude(x => x.PartyMailingAddress)
.ThenInclude(x => x.PropertyMailingAddress)
.IncludeFilter(y => y.PropertyMailingAddress.Where(z => z.Status == true)).ToListAsync();
*我們將需要所有嵌套實體,同時過濾,
目前使用的是 Net Core 2.2
您不能將Include
與IncludeFilter
混合使用。
在 EF Core 中, IncludeFilter
應自動添加所有路徑。
我們沒有 class 定義,因此很難准確了解關系,但查詢應如下所示:
var result = await db.Property.IncludeFilter(pm => pm.PropertyParty
.Select(x => x.Party)
.SelectMany(x => x.PartyMailingAddress)
.SelectMany(x => x.PropertyMailingAddress.Where(z => z.Status == true)).ToListAsync();
過濾是在數據庫中完成的。 所以要小心 EF Core 2.x,因為他們在 EF Core 3.x 中刪除了客戶端評估,這導致了一些問題。
如果您需要更多幫助,只需在我們的問題跟蹤器中提供可運行的解決方案: https://github.com/zzzprojects/EntityFramework-Plus/issues
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.