DocumentDB now has .Take() / $top= support, but OData attempts to sort by primary key when applying $top to DocumentDB's IQueryable
Example query: http://localhost/odata/MyEntitySet?$top=1
Example controller:
[EnableQuery]
public async Task<IQueryable<MyEntityDto>>Get()
{
/* (set up DocumentDB client) */
var queryable = Client.CreateDocumentQuery<MyEntityDto>("dbs/" + Database.Id + "/colls/" + Collection.Id);
return queryable;
}
Resulting error:
A first chance exception of type 'Microsoft.Azure.Documents.BadRequestException' occurred in Microsoft.Azure.Documents.Client.dll
Additional information: Message: {"Errors":["Primary key order-by is not supported."]}
Edit: fixed formatting, also you should note that you'll need the very latest client sdk for this, 1.5.2
Edit 2: for anyone who finds this via a search engine, I found that this behavior can be disabled with an option: https://msdn.microsoft.com/en-us/library/system.web.http.odata.query.odataquerysettings.ensurestableordering(v=vs.118).aspx which resolves the problem.
Hi @nickkin-msft it is by design that we will order the result by primary key if your apply top or skip, relative code is in https://github.com/OData/WebApi/blob/master/OData/src/System.Web.OData/OData/Query/ODataQueryOptions.cs#L318-L331
I found that this behavior can be disabled with an option: https://msdn.microsoft.com/en-us/library/system.web.http.odata.query.odataquerysettings.ensurestableordering(v=vs.118).aspx which resolves the problem.
You can close this bug. Thanks!