Grouping over multiple fields in linq
Here's some code that I keep forgetting from time to time. :-) Here's the basic code for grouping over multiple fields in linq.
var fullGroupedUpdateBilling = (from ub in fullUpdateBilling
group ub by new { ub.Id, ub.ctranscode, ub.ctransdesc} into g
select new UBUpdateBillingReportItem
{
Id = g.Key.Id,
ctranscode = g.Key.ctranscode,
ctransdesc = g.Key.ctransdesc,
usage = g.Sum(t => t.usage),
amt = g.Sum(t => t.bbamt),
bbamt = g.Sum(t => t.amt),
hasbb = hasBB
});
Written by Michael Griffith
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#