I have an application making use of BreezeJs querying a standard WebApi controller backed by an EntityFramework and SQL store. When I use an order by clause, I wish NULL and empty string values to always be sorted last (for BOTH ascending and descending order).
In SQL or even EF server side this is not a difficult task. However, I’ve not been able to locate the documentation for BreezeJs which shows how this can be accomplished.
The ideal solution would be some way to modify my EF context so this is the default behavior when any Order By is detected, prior to query hitting the DB. Failing that, perhaps there’s a way I’ve missed in Breeze itself to specify how nulls are handled in the results.
Worst case, I’ll need to write two separate queries client side and merge the results, one for with and one without values in the specified column.
Suggestions?
This is an interesting question.
Breeze currently has a class called LocalQueryComparisonOptions that may be used to control whether client side ordering is case sensitive and whether string comparisons should be SQL92 compliant. The idea here is that this class should be used to match whatever ordering rules are used by whatever server implementation you have selected.
It sounds like what you want is to also have the option to completely control local ordering of a query, probably by providing your own ordering function. If this is the case, please add this to the breeze User Voice and vote for it. This seems very reasonable and if it gets enough votes I think it makes sense to add it to the product.
Note that you will still need to insure that EF ( or whatever backend you are using) adheres to these same ordering rules.
Also, out of curiosity, how do you make EF always order nulls this way?