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.
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
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.