linq query to get monthly expenses in vb.net
I have a collection of order objects (properties - date, amount and vendor). I need to prepare a report showing spend by vendor by month since 01/01/2009. Ho开发者_Python百科w can i get the results using LINQ?
Something like:
var minDate = new DateTime(2009, 1, 1);
var query = from order in db.Orders
where order.Date >= minDate
group order by new { order.Vendor,
order.Date.Month, order.Date.Year } into g
select new { g.Key.Vendor, g.Key.Month, g.Key.Year,
g.Sum(x => x.Amount) };
That will group by vendor, month and year.
精彩评论