好好学习,天天向上!

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);

 

posted @ 2020-03-17 10:43  刘下来  阅读(1260)  评论(0编辑  收藏  举报