簡體   English   中英

在 ThenInclude 上過濾,使用 EntityFrameworkPlus IncludeFilter

[英]Filtering On ThenInclude, with EntityFrameworkPlus IncludeFilter

我正在嘗試向下過濾三個子級別,並僅找到 PropertyMailingAddress.Status== True 的子元素。

如何將過濾器向下轉換三個級別並使用 EntityFrameworkPlus IncludeFilter 進行嵌套過濾? 最有效的方法是什么?

Class 結構嵌套如下:

  1. 財產
  2. 財產黨
  3. 聚會
  4. 聚會郵寄地址
  5. PropertyMailingAddress <--- 狀態應該等於真(任何狀態 == False 的孫子 PropertyMailingAddress 節點,都應該從這個嵌套的孫子分支中刪除,保留為 True 的 PropertyMailingAddress 節點)

這種原始方式不起作用:

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

您不能將IncludeIncludeFilter混合使用。

在 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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM