开发者

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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜