LINQ根据时间排序问题(OrderBy、OrderByDescending)

直接上代码:

db.GetList<Draw2D>(x => x.ProductId == id && x.EditionNo == no)
    .OrderBy(x => x.CreateTime.Desc())
    .ToList();

这个无法排序!!!

return db.GetList<Draw2D>(x => x.ProductId == id && x.EditionNo == no)
        .OrderByDescending(x => x.CreateTime)
        .ToList();

这个可以!

错误原因:

之前公司SDK是那样封装的,现在回归LINQ的原来写法,不需要画蛇添足。。。。

OrderBy默认就是正序不需要再写```Asc()或Desc()```,如果要倒序排,就用OrderByDescing()

var lists = db.GetList<Draw2D>(x => x.ProductId == id)
            .OrderBy(x => x.EditionNo)  //这里把 .Asc() 去掉即正常
            .ThenBy(x => x.CreateTime);
原文地址:https://www.cnblogs.com/stickcsharp/p/12509136.html