LINQ statement help should be rather simple

Hello all,

I am using entity framework and I have entities with navigation properties aka table keys.   I have the following statement:

var loans = _uow.Loans.GetAll().Where(loan => loan.PoolID == poolId
                   && loan.IsActive && (!loan.LoanWorkflows.All(lw => lw.LoanId == loan.LoanID && 
                         lw.PoolWorkflowId == poolWorkflow.PoolWorkflowId)));

This is not working as I am expecting.   So what I want is I want all active Loans from the Loans table that do not have a corresponding record in the LoanWorkflows table where Loan.LoanId = LoanWorkflow.LoanId and LoanWorkflow.PoolWorkFlowId = the passed in value I have above for that.   Also there might not be at all a LoanWorkflowId object it may be null but I think that would be handled.   My statement right now is not working right for example if I have a truncated LoanWorkflow table I am getting 0 loans back that is not right.

Thanks all.
Who is Participating?
Fernando SotoConnect With a Mentor RetiredCommented:
Hi sbornstein2;

I think you may be looking to use the Any method and not All as shown below.

var loans = _uow.Loans.GetAll()
                .Where(loan => 
                 loan.PoolID == poolId && 
                 loan.IsActive && 
                 (!loan.LoanWorkflows.Any(lw => lw.LoanId == loan.LoanID && 
                   lw.PoolWorkflowId == poolWorkflow.PoolWorkflowId)

Open in new window

sbornstein2Author Commented:
thank you
Fernando SotoRetiredCommented:
Not a problem, glad I was able to help.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.