[英]sorting integer or decimal column in nhibernate
I am trying to sort decimal or integer column. 我正在尝试对十进制或整数列进行排序。 but while sorting ascending zero is coming last. 但是在排序升序为零时排在最后。
the code is: 代码是:
criteria.AddOrder(Order.Asc(Projections.Cast(NHibernateUtil.Decimal, Projections.Property("cloumn1")))));
output: 输出:
35342860
36870852
87654321
213123213
0
0
Any issue in code? 代码有问题吗? or what is solution? 或什么是解决方案?
These are most likely null values. 这些很可能是空值。 You could look at using a conditional restriction or making this a non nullable column with a default of 0, which would seem to be what you are after. 您可以查看使用条件限制,或将其设置为默认值0的不可为空的列,这似乎正是您所追求的。
Conditional restriction would be something like this 有条件的限制就是这样
.AddOrder
(
Order.Asc
(
Projections.Conditional
(
Restrictions.IsNull("cloumn1"),
Projections.Constant(1),
Projections.Constant(0)
)
)
)
which if you put in as first ordering will put the nulls at the top and displayed as 0 如果您按第一顺序输入,则会将null放在顶部并显示为0
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.