本文介绍了LINQ中的最大日期记录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在MS Sql Server中将此表命名为具有以下值的样本:
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 2012/01/03 5:12:41 Desc3
4 2012/01/03 5:12:43 Desc4
现在我要编写LINQ查询,结果将是这样:
Now I want to write LINQ query that result will be this:
4 2012/01/03 5:12:43 Desc4
我写了这个,但是不起作用:
I wrote this but it doesn't work:
List<Sample> q = (from n in Sample.Max(T=>T.Date)).ToList();
推荐答案
使用:
var result = Sample.OrderByDescending(t => t.Date).First();
这篇关于LINQ中的最大日期记录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!