In a list of transaction objects, I am attempting to group by BatchNo then sum the Amounts.
public class Extract
{
// Notable fields in TRANSACTION are: String mBatchNo, String mAmount
private List<Transaction> Transactions;
public void testTransactions()
{
// Sum of amounts grouped by batch number
var sGroup = from t in Transactions
group t by t.mBatchNo into g
select new { batchNo = g.Key,
totalAmount = g.Max(a => (Int32.Parse(a.mAmount)))};
}
}
At this point, I step into the code look through the locals window to see what my result set is to check against the file I've imported to this object.
The last batch in the file has 3 records, 100 amount each which can be seen drilling into the Transactions list object. However drilling down into the sGroup result finds the same batch to have 100 amount total (Should be 300). What have I messed up in this query?
Note that I've stored this as a string since we're zero filled to the left of a 8 character field. For export reasons I decided to store as a string. Though this can (and probably will) be changed it does not answer my question: How to make this query aggregate the sum into sets by BatchNo?