3
votes

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?

1
I've a similar scenario. Have you concluded any solution? If yes, can you please share it?user1672994
Unfortunately, no solution yet. I have not had any time to look more at it, but will post back here if I ever find a solution.Stein Rustad

1 Answers

0
votes

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());
}

https://docs.microsoft.com/en-us/aspnet/web-api/overview/odata-support-in-aspnet-web-api/supporting-odata-query-options