I was wondering if there is any way to implement pagination in C# against DocumentDB with, or without, their Linq provider?
Scenario: I have an API which supports pagination, the user sends in the page they want to look at along with a pageSize, such as:
public virtual async Task<HttpResponseMessage> Get(int? page = DefaultPage, int? pageSize = DefaultPageSize)
I then use those parameters to paginate the data in the data access layer with the following code:
return query.Skip((pageNumber - 1) * pageSize).Take(pageSize);
"What is the problem then?", you might ask. Well, this approach and code works perfectly whilst using EF and SQL. The problem is that I want to start using DocumentDB but their Linq-implementation has no support for Skip. The only examples I've seen includes using the TOP keyword or continuation tokens which does not fit well with me allowing users to send in a pageNumber and pageSize.
Is there any implementation that will still allow my users to provide pageNumber
and pageSize
in the request?
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…