LINQ Using Max() to select a single row

前端 未结 6 1444
轻奢々
轻奢々 2020-12-02 16:13

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

6条回答
  •  甜味超标
    2020-12-02 16:48

    Simply in one line:

    var result = table.First(x => x.Status == table.Max(y => y.Status));
    

    Notice that there are two action. the inner action is for finding the max value, the outer action is for get the desired object.

提交回复
热议问题