I\'m experimenting with Linq and am having trouble figuring out grouping. I\'ve gone through several tutorials but for some reason can\'t figure this out.
As an exam
Actually, although Thomas' code will work, it is more succint to use a lambda expression:
var totals =
from s in sites
group s by s.SiteID into grouped
select new
{
SiteID = grouped.Key,
Last30Sum = grouped.Sum( s => s.Last30 )
};
which uses the Sum extension method without the need for a nested LINQ operation.
as per the LINQ 101 examples - http://msdn.microsoft.com/en-us/vcsharp/aa336747.aspx#sumGrouped