c# lambda reading each row with GROUP BY and SUM -
this working query using in management studio.
select top 5 productcode, sum(productsales) sales sellinglog (salesyear = '2014') group productcode order sales desc
i want convert query above lambda, can't seems make works. lambda still lacks of order , select productcode
var topproducts = sellinglog .where(s => s.salesyear == 2014) .groupby(u => u.productcode) .select(b => b.sum(u => u.productsales)).take(5) .tolist(); foreach(var v in topproduct) { //reading 'productcode' , 'sales' each row }
var topproducts = sellinglog .where(s => s.salesyear == 2014) .groupby(u => u.productcode) .select(g => new { productcode = g.key, sales = g.sum(u => u.productsales) }) .orderbydescending(x => x.productcode) .take(5) .tolist();
Comments
Post a Comment