Order by null/not null with ICriteria

Posted by Kristoffer on Stack Overflow See other posts from Stack Overflow or by Kristoffer
Published on 2010-04-08T16:39:00Z Indexed on 2010/04/08 16:43 UTC
Read the original article Hit count: 532

Filed under:
|
|

I'd like to sort my result like this:

  • First I want all rows/objects where a column/property is not null, then all where the colmn/property is null.
  • Then I want to sort by another column/property.

How can I do this with ICriteria? Do I have to create my own Order class, or can it be done with existing code?

ICriteria criteria = Session.CreateCriteria<MyClass>()
  .AddOrder(Order.Desc("NullableProperty")) // What do I do here? IProjection? Custom Order class?
  .AddOrder(Order.Asc("OtherProperty"));

© Stack Overflow or respective owner

Related posts about icriteria

Related posts about nhibernate