views:

1336

answers:

2

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.

+3  A: 

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.

Elie
+5  A: 

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.)

SoloBold
I realize it's been awhile but that link doesn't work. http://nhforge.org/doc/nh/en/index.html#querycriteria should do it.
JasonCoder
Thank you JasonCoder :)
SoloBold