Software Engineering, a personal journey

C# LINQ descending order

This is a short late night post

The site has had an annoying bug, the articles are ordered earliest first. LINQ has a quick solution to this OrderByDescending and here's it in use:
        public ActionResult Index(int? page)
            var pageItems = News.ArticleList().OrderByDescending(c => c.Created);
            var articleModels = pageItems as IList<ArticleModel> ?? pageItems.ToList();
            var pager = new Pager("Home", articleModels.Count(), page);

            var viewModel = new IndexViewModel();
                viewModel.Items =
                    articleModels.Skip((int) ((pager.CurrentPage - 1) * pager.PageSize)).Take((int) pager.PageSize);
                viewModel.Pager = pager;
            return View(viewModel);


Have your say


Comment here (140 chars only)*:

Email address: