2

This is my sql syntax

select DepartmentId, max(fromdate) from iwof.DateSnippet group by DepartmentId 

and this is the result that I get

1   2013-09-09 14:53:52.813 
2   2014-02-07 14:37:21.740
3   2014-02-07 14:37:21.737
4   2014-02-07 14:37:21.740
5   2014-02-07 14:37:21.743
6   2014-02-07 14:37:21.743
eugenekgn
  • 1,652
  • 2
  • 17
  • 38
  • this should help http://stackoverflow.com/questions/7325278/group-by-in-linq –  Feb 07 '14 at 16:21
  • http://stackoverflow.com/questions/157786/how-do-i-get-the-max-row-with-a-group-by-in-linq-query – eugenekgn Feb 07 '14 at 16:34

1 Answers1

1

The syntax you use is incorrect. Format closer to this, and it should do the trick

var results = from p in iwof.DateSnippet
          group p by p.DepartmentId into g
          select new { DepartmentId = g.Key, MaxFromDate = g.Max(fromdate) };
Alexandru Puiu
  • 741
  • 6
  • 16