开发者

linq query to get monthly expenses in vb.net

开发者 https://www.devze.com 2023-01-16 04:06 出处:网络
I have a collection of order objects (properties - date, amount and vendor). I need to prepare a report showing spend by vendorby month since 01/01/2009.

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

精彩评论

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