max date record in LINQ

后端 未结 6 1292
一个人的身影
一个人的身影 2021-02-03 21:35

I have this table named sample with these values in MS Sql Server:

 ID    Date    Description
1    2012/01/02 5:12:43    Desc1
2    2012/01/02 5:12:48    Desc2
3         


        
6条回答
  •  说谎
    说谎 (楼主)
    2021-02-03 22:26

    To get the maximum Sample value by date without having to sort (which is not really necessary to just get the maximum):

    var maxSample  = Samples.Where(s => s.Date == Samples.Max(x => x.Date))
                            .FirstOrDefault();
    

提交回复
热议问题