ASP.NET MVC - Model.OrderBy Date has no effect

两盒软妹~` 提交于 2019-12-01 17:02:55

This code looks good. You should check what is really in the Date field and make sure you do not for example only set the Date of the DateTime object on the database level, that would result in all DateTime objects of a certain date to point to 00:00:00 thus the LINQ would not know how to sort them.

Looking at the answer you provided (which FYI should be moved into the question as an edit), you should apply a ThenBy, rather than a new OrderBy:

var articles = db.Articles.OrderByDescending(a => a.Date).ThenBy(a => a.Id).ToList();
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!