实体框架在嵌套实体上使用Where子句

时间:2018-06-07 03:10:29

标签: c# entity-framework entity-framework-6

我正在尝试使用以下

过滤检索中的子对象
var loanExtractExample = be.LoanCategoryMonitors
                .Where(lcm => lcm.LoanNumber == 5000435)
                .Include(l => l.Loan)
                .Include(le => le.LoanExtracts)
                .Select(le => le.LoanExtracts.Borrowers.Where(b => b.BorrowerNum == 1))
                .ToList();

但是当我检查实体收藏时,有2个借款人。一个是BorrowerNum 1,一个是BorrowerNum = 3.

我错过了什么能够将借款人减少到正确的借款人?

1 个答案:

答案 0 :(得分:0)

借款人的选择我相信会将借款人退回贷款类别监控器,其中监控器有一个ID为1的借款人。我相信你所寻找的是:

create_table :products do |table|
  table.string :name
end

由于您没有检索贷款类别监视器,因此不需要包含,但您可能希望为返回的借用者的子引用添加任何.Include()语句。 (在var matchingBorrowers = be.LoanCategoryMonitors .Where(lcm => lcm.LoanNumber == 5000435) .SelectMany(le => le.LoanExtracts.Borrowers) // Borrowers for loan extracts against loan 5000435... .Where(b => b.BorrowerNum == 1)) // Of those borrowers, those with BorrowerNum = 1. .ToList(); 之后)