1.Linq中的排序字段的优先级与SQL语句不同,SQL中前者优先而Linq中后者优先,如下语句有等价的排序效果。

--SQL:

select a.is_topmost, a.* from tab_com_attachment a 

order by NVL(a.is_topmost, 0) desc, a.last_modify desc;

//Linq:

var qFiles = from a in db.Attachments

                   where idList.Contains(a.Id)

                   select a;

var tFiles = from a in qFiles.ToList()

                   orderby a.LastModify descending

                   orderby a.IsTopmost.GetValueOrDefault(false) descending  

                   select new FileTransportInfo()

                  {

                      FileId = a.Id,

//......

    };

注意:用可空类型排序时需要先转换成不可空的,而NHibernate3.3不支持直接转换,需要先用ToList()转换成本地数组再排序。

相关文章:

  • 2022-12-23
  • 2021-12-03
  • 2021-09-06
  • 2021-10-29
  • 2022-12-23
  • 2022-02-11
  • 2022-02-25
  • 2022-12-23
猜你喜欢
  • 2021-12-20
  • 2022-12-23
  • 2021-07-23
  • 2022-12-23
  • 2021-05-12
  • 2021-12-31
  • 2022-12-23
相关资源
相似解决方案