我正在尝试找出一种更好的方法来排序我的SQL查询结果。
到目前为止我已经
了List<ArticlePost> articlePosts = new List<ArticlePost>();
IQueryable<ArticlePost> query = from ArticlePost in ArticlePostTable select ArticlePost;
foreach (ArticlePost ArticlePost in query)
articlePosts.Add(ArticlePost);
articlePosts = articlePosts.OrderByDescending(ArticlePost => ArticlePost.atclID).ToList();
这是使用linq对列表进行排序的好方法还是有什么方法可以改进它?
答案 0 :(得分:5)
以下是什么问题?
var articlePosts = ArticlePostTable.OrderByDescending(ap => ap.actlId).ToList();
答案 1 :(得分:2)
var articlePosts = (
from post in ArticlePostTable
orderby post.atclID descending
select post)
.ToList();
答案 2 :(得分:0)
请改为尝试:
List<ArticlePost> articlePosts =
ArticlePostTable
.OrderByDescending(ArticlePost => ArticlePost.atclID)
.ToList();