簡體   English   中英

在 Entity Framework Plus 中的 IncludeFilter 上使用 AND (&&) 運算符不會帶回嵌套/子對象

[英]Using the AND (&&) operator on IncludeFilter in Entity Framework Plus not bringing back nested / child object

我只是在 Entity Framework Plus 上找到了自己的腳,以帶回具有一組復雜約束/要求的數據。 我能夠成功使用它,但是在 IncludeFilter() 方法中使用 && 運算符時,我無法返回嵌套/子對象。

我有一個 Company 對象 > 每個都有多個 CommunicationLink 對象 > 每個 CommunicationLink 對象都有一個 Communication 對象。 我已經發現添加多個“包含過濾器”可用於復制“或”功能(||),但我一生都無法使用 AND 運算符來過濾結果並獲取嵌套對象通過。 下面是示例代碼:

示例 1:

//2 WHERE CLAUSES
var companiesData = _dbContext.Companies
     .IncludeFilter(comp => comp.CommunicationLinks
                .Where(cmli =>
                    string.Equals(cmli.Communication.Action, "PhoneOut")
                )
                .Where(cmli => cmli.UserId == comp.AccountManager) 
                .Select(comm => comm) //I believe this is where the problem lies
      )
      .Where(co =>
           string.Equals(co.Type, "Customer")
           && string.Equals(co.Status, "Active")
           && co.Deleted != 1 
       )
       .OrderBy(c => c.Name);

示例 2:

   //USING && INSTEAD OF 2 WHERE CLAUSES
    var companiesData = _dbContext.Companies
         .IncludeFilter(comp => comp.CommunicationLinks
                    .Where(cmli =>
                        string.Equals(cmli.Communication.Action, "PhoneOut")
                        && cmli.UserId == comp.AccountManager 
                    )
                    .Select(comm => comm) //I believe this is where the problem lies
          )
          .Where(co =>
               string.Equals(co.Type, "Customer")
               && string.Equals(co.Status, "Active")
               && co.Deleted != 1 
           )
           .OrderBy(c => c.Name);

我試圖過濾結果以僅帶回 CommunicationLink 記錄,其中子 Communication.Action 字段為“PhoneOut”且 Communication.UserId 等於 Company.AccountManager (Id) 中的值。 過濾后的結果運行良好,但是 Communication 對象(我希望通過 .Select() 方法獲得)對於這些記錄返回 null。

今天早上在這個問題上掙扎了一段時間后,我解決了它。

//2 WHERE CLAUSES
var companiesData = _dbContext.Companies
     .IncludeFilter(comp => comp.CommunicationLinks
                .Where(cmli =>
                    string.Equals(cmli.Communication.Action, "PhoneOut")
                )
                .Where(cmli => cmli.UserId == comp.AccountManager) 
                .Select(comm => comm.Communication) //forgot Communication!!
      )
      .Where(co =>
           string.Equals(co.Type, "Customer")
           && string.Equals(co.Status, "Active")
           && co.Deleted != 1 
       )
       .OrderBy(c => c.Name);

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

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