title: IQueryable that sums the amount where two unique id's match C#
body: <p>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.  </p>
  
  <p>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. </p>
  
  <p>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.</p>
  
  <p>Please help.  Below is my Query, it's the amount column I want to sum.</p>
  
  <p>Example data on the left, what i want on the right</p>
  
  <pre><code>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&lt;BatchPayment&gt; query = _db
                  .BatchPayments
                  .Where(
                      bp =&gt; ValidBatchStatuesIds.Contains(bp.Batch.BatchStatusId)
                          &amp;&amp; (!OnlineBatchTypes.Contains(bp.Batch.BatchTypeId)
                              || (OnlineBatchTypes.Contains(bp.Batch.BatchTypeId) &amp;&amp; bp.Amount &gt; 0.00m))
                  );
  </code></pre>