LINQ - Month in words format - Asked By Shan on 02-Jun-11 03:33 AM

Hi,

 I want to convert this to LINQ

SELECT SUM(currentvalue) AS Expr1, CONVERT(VARCHAR(3), DATENAME(MM, ReceivedDate), 100) AS Expr2, id

FROM Table1

GROUP BY CONVERT(VARCHAR(3), DATENAME(MM, ReceivedDate), 100), id

pete rainbow replied to Shan on 12-Jun-11 08:55 PM
something like this maybe? give or take spellings of columns etc

var valuesByMonth =
    from p in dt
    group p by new {p.ReceivedDate.Month, id = p.id} into g
    select new {currentValue = g.Sum(p => p.CurrentValue) , g.Key.Month , g.Key.id };

or for data in DataTable
 
var valuesByMonth =
    from p in dt.AsEnumerable()
    group p by new {p.Field<DateTime>("ReceivedDate").Month, id = p.Field<int>("id")} into g
    select new {currentValue = g.Sum(p => p.Field<double>("CurrentValue")) , g.Key.Month , g.Key.id };