Difference between PageSize and MaxTop
Asked Answered
R

3

6

What's the difference between [EnableQuery(PageSize=20)] and [EnableQuery(MaxTop=20)]?

As far as I can tell they both set a max limit on the result.

Calling GET odata/Products?$top=100 on either of them both give me only 20 results.

Restive answered 20/3, 2015 at 11:27 Comment(1)
Try modifying your request to GET odata/Products and you will instantly figure out the difference.Avoidance
E
5

The difference is on Server Paging Driven Mode

OData provide two modes of server-paging: client-driven and server-driven.

PageSize controls the page size that server use in server-driven mode. Not used if the caller provide $top parameter.

MaxTop controls the max $top value that caller can specify in client-driven mode.

Client-driven mode

The caller will provide the page size parameter ($top). The server will use the $top to make paging. The caller may provide $skip parameter to get next page.

Example:

First Page: http://server/odata/Entity?$top=20

Next Page: http://server/odata/Entity?$top=20&$skip=20

Server-driven mode

The caller will not provide page size parameter ($top). The server will use PageSize parameter to make paging. Responsor includes a @data.nextLink entry in JSON result to caller get the next page data.

Example with PageSize = 20:

First Page: http://server/odata/Entity

Server will return a @data.nextLink to the next page: http://server/odata/Entity?$skip=20

Electrometer answered 16/8, 2018 at 14:0 Comment(0)
R
3

I think the answer of @jvitor83 makes sense.

MaxTop only impacts the scenarios in which the request Uri contains $top. If the $top value exceeds the MaxTop value, you may get the following error message:

{
  "error":{
    "code":"","message":"The query specified in the URI is not valid. The limit of '20' for Top query has been exceeded. The value from the incoming request is
'100'."
  }
}

However, PageSize impacts the final query result. For example, you set [EnableQuery(PageSize=20)], it means you want the server to return 20 results if the number of final result exceeds 20.

And the final query result is decided by whether $top is used. If not $top set, the final query result is the total data set. And, If $top=x set and the x less than or equal to MaxTop, the final result is the top x.

Rayford answered 30/3, 2015 at 9:28 Comment(0)
P
2

As described in MSDN:

MaxTop = Gets or sets the max value of $top that a client can request.

PageSize = Gets or sets the maximum number of query results to send back to clients.

Phenylketonuria answered 23/3, 2015 at 8:35 Comment(1)
That doesn't really explain the difference :/Wellfixed

© 2022 - 2024 — McMap. All rights reserved.