Using PostgreSQL 8.3 it's possible to add an extra parameter to the order by clause defining whether to order with nulls first or last.
At the moment it is not possible to use the Order object for manipulating the order clause, which would have been a possible solution.
Since not all DBMS support this feature (and the feature is different between the DBMS's), I have no clue how a solution to this would be approached.
I guess it could be solved somehow by giving the user the ability to append/inject something to the end of the order by clause.
My current solution has been to inherit from the Order class, overwrite the ToSqlString and append the "nulls last" to the sql string.
Kenneth Siewers Møller added a comment — :
I've tried a two different solutions and both are working.
One way to order with nulls last is by using the following construct:
order by case when tbl1.col1 is null then 1 else 0 end, col1 asc
I've tried implementing it in my custom order class, and it works as expected. Does anyone have any comments on this?
Basically what I've done is this:
fragment.Append(" case when ").Append(criteriaQuery.GetColumn(criteria, propertyName)).Append(" is null then 1 else 0 end, ");
fragment.Append(columns);
As I have not idea what implications this might have, I don't know how it works in subselects etc.
Fabio Maulo added a comment — :
and why you don't do it explicitly in your query instead inject something in the SQL ?
Kenneth Siewers Møller added a comment — :
Well, I guess what I'm asking is if there's a way to do it more generally? I am thinking of think an extension to the Order class... perhaps like "Order.Asc("PropertyName").Nulls.Last()" (or something similar) would be very nice.
Kenneth Siewers Møller created an issue — :