I prefer to get maxDate first, as you originally stated. I do not see any problems using the syntax that you already used.
However, if you want, you can shorten the code as follows:
var wantedObject = myEnumerable.FirstOrDefault(x => x.TheDateTimeProperty == myEnumerable.Max(x => x.TheDateTimeProperty));
(This code is not verified, some casting may be required)
Or you can write a stored procedure and take data from it.
However, I do not prefer OrderByDescending. At first. This is normal if physically your data in the table is sorted by your specified property. But if not, then your sql table will need to sort the sort and probably get a big load. Especially if the table has more than 1 m of records, and DateTime is stored in ascending order in the physical.
Using max can lead to a better (faster / easier) result than to it.
Fendy
source share