help converting sql to linq expression with count

Posted by Philip on Stack Overflow See other posts from Stack Overflow or by Philip
Published on 2010-04-14T18:55:22Z Indexed on 2010/04/14 19:03 UTC
Read the original article Hit count: 476

Filed under:
|

I am trying to convert the following SQL into a LINQ expression

SELECT COUNT(ID) AS Count, MyCode

FROM dbo.Archive

WHERE DateSent>=@DateStartMonth AND DateSent<=@DateEndMonth

GROUP BY MyCode

and I have been trying to follow this webpage as an example

http://stackoverflow.com/questions/606124/converting-sql-containing-top-count-group-and-order-to-linq-2-entities

I got this so far but I am stuck on understanding the new part

                var res=(from p in db.Archives
                 where (p.DateSent>= dateStartMonth) && (p.DateSent< dateToday)
                 group p by p.MyCode into g
                         select new { ??????MyCode = g.something?, MonthlyCount= g.Count() });

Thanks in advance for helping greatly appreciated Philip

© Stack Overflow or respective owner

Related posts about linq-to-sql

Related posts about LINQ