NHibernate ICriteria - does sorting allow null?

Using NHibernate ICriteria and adding .AddOrder ... I want to sort by a property that sometimes has a value of zero with all filled in at the top. Will .AddOrder allow me to do this? If not, is there an alternative?

The sorting options for ILists are poor.

+4
source share
2 answers

You must first get nonzero values ​​using this method. We use sorting this way in my project and have no problem with null values ​​... they end up in the end.

+3
source

If you use something similar to:

IList cats = sess.CreateCriteria(typeof(Cat)) .AddOrder( Order.Desc("PropertyName") ) .List(); 

Objects with NULL for this property will be the last in the list.

(Adapted in part from the NHibernate documentation .)

+5
source

Source: https://habr.com/ru/post/1277296/


All Articles