I\'m using LINQ on an IQueryable returned from NHibernate and I need to select the row with the maximum value(s) in a couple of fields.
I\'ve simplified the bit tha
You can group by status and select a row from the largest group:
table.GroupBy(r => r.Status).OrderByDescending(g => g.Key).First().First();
The first First()
gets the first group (the set of rows with the largest status); the second First()
gets the first row in that group.
If the status is always unqiue, you can replace the second First()
with Single()
.