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?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Fernando SotoRetiredCommented:
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


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
sbornstein2Author Commented:
thank you
Fernando SotoRetiredCommented:
Not a problem, glad I was able to help.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.