Reputation: 8285
I am trying to figure out a better way of ordering the results of my sql query.
So far I have
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();
Is this a good way of sorting my list using linq or is there any way i can improve on it?
Upvotes: 1
Views: 56
Reputation: 39023
What's wrong with the following?
var articlePosts = ArticlePostTable.OrderByDescending(ap => ap.actlId).ToList();
Upvotes: 5
Reputation: 14292
Try this instead :
List<ArticlePost> articlePosts =
ArticlePostTable
.OrderByDescending(ArticlePost => ArticlePost.atclID)
.ToList();
Upvotes: 0
Reputation: 172716
var articlePosts = (
from post in ArticlePostTable
orderby post.atclID descending
select post)
.ToList();
Upvotes: 2