AutoQueryable
AutoQueryable copied to clipboard
Orderby doesn't work with more than 1 column
I have a bug with multi-column sort in my project and looking at the code it seems that the order of multiple fields is not respected.
If you look here at the loop that applies sort: https://github.com/trenoncourt/AutoQueryable/blob/1383b3d9ad12c1dcc38c49344342b31c4c95215d/src/AutoQueryable/Helpers/QueryBuilder.cs#L273
You will notice that the ordering of columns
is in fact the order of declared properties on the type:
https://github.com/trenoncourt/AutoQueryable/blob/1383b3d9ad12c1dcc38c49344342b31c4c95215d/src/AutoQueryable/Helpers/QueryBuilder.cs#L256
Moreover, even if you fixed this by iterating orderClause
, it would still be incorrect because it's a Dictionary<string, bool>
. When the query string is parsed, each column in orderby
is put into a Dictionary
but Dictionary
doesn't guarantee iteration order. So as soon as it's parsed, the ordering of orderby
fields is lost.