I have a table in which I am querying. Each payment has a total number and a negative number representing a fee. At the moment my query pulls the needed query without the negative number.
With the change I recently got I need to instead of just select the positive numbers I need to add the positive and negative numbers together where the batchId's match in the single table.
I have been working on it for a couple hours and everything I have tried I end up summing everything in the query and not just the negative and positive numbers where the batch id's match.
Please help. Below is my Query, it's the amount column I want to sum.
Example data on the left, what i want on the right
batchId Amount batchId Amount
1 2.23 1 1.00
1 -1.23 2 3.00
2 5.43m 3 4.00
2 -2.43
3 6.60
3 -3.60
IQueryable<BatchPayment> query = _db
.BatchPayments
.Where(
bp => ValidBatchStatuesIds.Contains(bp.Batch.BatchStatusId)
&& (!OnlineBatchTypes.Contains(bp.Batch.BatchTypeId)
|| (OnlineBatchTypes.Contains(bp.Batch.BatchTypeId) && bp.Amount > 0.00m))
);