Linq中Orderby使用

LINQ查询表达式中,orderby子句可以对查询结果进行排序。排序方式可以为“升序”或“降序”,且排序的键可以为一个或多个。

注意:LINQ查询表达式对查询结果的默认排序方式为“升序”。

实例:

1                    var values = from u in users
2 
3                                                 where u.ID < 6
4 
5                                                 orderby u.Username descending
6 
7                                                 select u;

(2)实例二多个字段排序

1                    var values = from u in users
2 
3                                                 where u.ID < 6
4
5                                                 orderby u.Username descending,u.ID ascending
6 
7                                                 select u;

 

posted @ 2012-06-28 17:33  Seasons1987  阅读(1563)  评论(0编辑  收藏  举报