14

I can't figure out how to add a OrderBy clause to a TableQuery with Azure Table Storage.

According to their documentation Azure supports OData $orderby. If I try to hack it by adding $orderby=PartitionKey to the TableQuery Where clause the '$' is HTTP-encoded and I get a 400 server error because of it - so hacking it in wont work. Here is what my hack produces:

GET /devstoreaccount1/NewTable3?$filter=PartitionKey%20ne%20%27pkey992%27%24orderby%3DName&$select=Name%2Cregistered%2CPartitionKey%2CRowKey%2CTimestamp HTTP/1.1

Does TableQuery support OrderBy, and if yes then how?

1 Answers1

22

Does TableQuery support OrderBy, and if yes then how?

No. As of today, Table Service does not support Order By. Please see the list of supported LINQ Operators here.

What you would need to do is fetch the data (which will be sorted by PartitionKey and RowKey) and apply the sorting on the client side.

Ian Kemp
  • 28,293
  • 19
  • 112
  • 138
Gaurav Mantri
  • 128,066
  • 12
  • 206
  • 241
  • Yes, I found this list of supported OData query options for the Azure Table Service now and $orderby is not on it, shame. https://msdn.microsoft.com/en-us/library/azure/dd894031.aspx –  Apr 26 '15 at 12:11
  • Yes, another API half done by Microsoft :( – vtscop Dec 04 '22 at 22:41