0

If I have the following tables/entities:

Invoice
- InvoiceId (PK)
- InvoiceAmount

InvoicePayment
- InvoicePaymentId (PK)
- InvoiceId (FK)
- PaymentAmount

How can I construct a Linq to Entity query that selects invoices with an outstanding amount - bearing in mind that the existence of a payment does not indicate that the invoice does not have an outstanding amount (i.e. partial payment are possible).

1 Answer 1

1

I would go for something along the lines of this

from i in invoices
where i.Payments.Sum(p=>p.PaymentAmount) < i.InvoiceAmount
select i;
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks @Luke McGregor, I was applying too much thought to it and trying to to something with .any() which isn't necessary.
Nah you definitally want a sum here, You can do the same as this in full fluent syntax but i think it looks readable like it is

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.