Reputation: 61
This question was previously posted here but I am repeating the question and a summary of the discussion here to have a complete question.
I have set up a ODataController in ASP.NET WebAPI with DocumentDB/CosmosDB as a backend. It works quite ok, I return the result of CreateDocumentQuery and $select,$top,$orderby and $filter work fine.
However, $skip does not. I know that this is a planned feature (Vote here) but I would like to know if there is any temporary workaround.
My plan was to have a "continuationToken" parameter to my OData controller action. I would then pass this using FeedOptions.RequestContinuation to CreateDocumentQuery. However, CreateDocumentQuery does not return a response token. I then tried with ReadDocumentFeedAsync, which does return a response token, but it does not return a IQueryable.
This is an example of api code inside a ODataController:
public IQueryable<Result> FindResults(Uri collectionUri, string continuationToken)
{
FeedOptions feedOptions = new FeedOptions();
feedOptions.MaxItemCount = 100;
feedOptions.RequestContinuation = continuationToken;
var query = client.CreateDocumentQuery<Result>(collectionUri, queryString, feedOptions).AsDocumentQuery();
return query as IQueryable<Result>;
}
However, what would the client code look like? I.e. what is the http-request required to keep the IQueryable alive to be able to use the continuationToken when paging? I guess I could store the result of ReadDocumentFeedAsync in memory and return a IQueryable to that, but is there a better solution?
Upvotes: 4
Views: 1203
Reputation: 304
Did you look at the PageResult object?
For non-OData formats, it is still possible to support next-page links and inline count, by wrapping the query results in a PageResult object. However, it requires a bit more code. Here is an example:
public PageResult<Product> Get(ODataQueryOptions<Product> options)
{
ODataQuerySettings settings = new ODataQuerySettings()
{
PageSize = 5
};
IQueryable results = options.ApplyTo(_products.AsQueryable(), settings);
return new PageResult<Product>(
results as IEnumerable<Product>,
Request.GetNextPageLink(),
Request.GetInlineCount());
}
Upvotes: 0