Tags: , | Categories: LINQ Posted on 6/10/2009 6:38 PM | Comments (0)

In one of my recent project, I had to retrieve Minimum and Maximum date from the result set using LINQ to SQL. I was really surprised how easy it was:

//Retrieve Minimum Date
var MinDate = (from d in dataRows select d.Date).Min();

//Retrieve Maximum Date
var MaxDate = (from d in dataRows select d.Date).Max(); 

In its simplest form, all you have to do is have .Min() or .Max() at the end of your LINQ query. That’s it.

Comments are closed