Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Please make it easier to implement server-driven paging with custom queries #377

Closed
brjohnstmsft opened this issue Jun 3, 2015 · 5 comments

Comments

Projects
None yet
4 participants
@brjohnstmsft
Copy link
Contributor

commented Jun 3, 2015

Currently server-driven paging is easy to support if you're using Web API OData with LINQ. ODataQueryOptions.ApplyTo() does the work for you. However, for services that don't use LINQ and instead process the OData query options ($filter, $orderby, etc.) and execute them directly, there is a lot of logic to implement. In particular, generating @odata.nextLink is non-trivial.

As a workaround, we are calling one of the overloads of ODataQueryOptions.GetNextLink() using reflection. It would be preferable if this method were public so that the logic can be re-used by anyone wanting to implement server-driven paging without using ApplyTo().

This is a small change, and if you agree with it I would be happy to make the change myself and submit a PR.

@congysu

This comment has been minimized.

Copy link
Contributor

commented Jun 6, 2015

Thanks @brjohnstmsft very much for the feedback. Please feel free to submit a PR.

@brjohnstmsft

This comment has been minimized.

Copy link
Contributor Author

commented Jun 8, 2015

Created: #384

@VikingsFan

This comment has been minimized.

Copy link
Contributor

commented Jun 10, 2015

Checkin 604b16c

@julealgon

This comment has been minimized.

Copy link

commented Oct 3, 2018

@brjohnstmsft I just ran into exactly the scenario you describe and created an issue here:
#1633

Could you please advise on how to properly support NextLink and TotalCount using a purely custom query there? Even if I rely on the Request.GetNextPageLink(int) call, it still generates the link everytime so I wonder if I'd have to handle when to show and not to show it manually?

In my particular case, I cannot apply the query options since I'm using Dapper and stored procs to do the heavy lifting.

@brjohnstmsft

This comment has been minimized.

Copy link
Contributor Author

commented Oct 3, 2018

@julealgon You will need to implement your own logic to determine when to set NextLink and TotalCount. Actually setting them is pretty easy:

request.ODataProperties().TotalCount = totalCount;
request.ODataProperties().NextLink = request.GetNextPageLink(pageSize);

where totalCount and pageSize are values that you have to calculate yourself. Tip: to detect whether results fit entirely within a page or are truncated (i.e. -- to help you decide whether you need a NextLink or not), request one more row/record/document from your underlying data store than the page size. If the extra row comes back, you need a NextLink, otherwise you don't.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.