Simplifying a LINQ expression that finds the largest date smaller than another date I have a LINQ 2 SQL query that needs to run a subquery in the where clause. The subquery just returns the largest date (from a date column) that is less than or equal to another date (an input to the function).

I originally had it like this (not this in the where clause of an outer query):

skew.CalibrationDate.Date == (from skew2 in db.Skew 
                              where skew2.CalibrationDate.Date &lt;= date.Date 
                              select skew2.CalibrationDate).Max()


And then simplified it to:

skew.CalibrationDate.Date == db.Skew.Select(s =&gt; s.CalibrationDate.Date)
                                    .Where(s =&gt; s &lt;= date.Date)
                                    .Max()


(note that the db.Skew table/object has multiple columns/properties but I'm only interested in the CalibrationDate for this clause and also that date is an input to the function that this is in, a regular DateTime variable).

Is it necessary for me to have all three of the Select(), Where() and Max() calls or is there some redundancy here? Could I put a lambda expression in the Max() call to get rid of one of the others?
Is this what you are looking for?

skew.CalibrationDate.Date == db.Skew
    .Where(s =&gt; s.CalibrationDate.Date &lt;= date.Date)
    .Max(s =&gt; s.CalibrationDate.Date)


Max will return the maximum value itself, not the object with the maximum date.