开发者

OrderByDescending on list of DateTime's not working?

In a lambda expression, how do you order by a list of DateTime values, rather than an object? For example, I want to get the most recent 3 pay dates on the following query:

 var hires = (from e in md.Employee
             where e.HireDate.Year == 2011
             select e.HireDate).Distinct();

 //at this point hires =
   6/3/2011
   5/15/开发者_JAVA百科2011
   6/1/2011
   7/1/2011

My assumption was that I could do .OrderByDescending(x => x).Take(3), but when I do so I don't get 7/1/2011 (just the first 3 above). It's like the OrderByDescending is being ignored.

What am I doing wrong?


Are you sure you are putting the orderby & distinct in the right order?

Try:

var hires = (from e in md.Employee
    where e.HireDate.Year == 2011
    select e.HireDate).Distinct().OrderByDescending(e => e);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜