Using NHibernate ICriteria and adding .AddOrder ... I want to sort by a property that is sometimes null with all the populated ones at the top. Will .AddOrder allow me to do this? If not is there an alternative?
The sorting options for ILists leave a lot to be desired.
If you use something similar to:
IList cats = sess.CreateCriteria(typeof(Cat))
.AddOrder( Order.Desc("PropertyName") )
.List();
The objects with NULLs for the given property will be last in the list.
(Taken in part from the NHibernate documentation.)
You should get the non-null values first by using that method. We use sorting in that way on my project, and have not had any issues with the null values... they get listed at end.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With