LinQ to Entities, Max Date Field, Grouped By whatever


/ Published in: C#
Save to your folder(s)



Copy this code and paste it in your HTML
  1. from p in PersonOrders
  2. // put your where clause here
  3. group p by p.PersonID into grp //could be grouped by anything, Grouping on Guid ID's is not a good idea
  4. let MaxOrderDatePerPerson = grp.Max ( g=>g.OrderDate )
  5.  
  6. from p in grp
  7. where p.OrderDate == MaxOrderDatePerPerson
  8. select p

URL: http://smehrozalam.wordpress.com/2009/12/29/linq-how-to-get-the-latest-last-record-with-a-group-by-clause/

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.