Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difference between PageSize and MaxTop

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.

like image 751
Snæbjørn Avatar asked Mar 20 '15 11:03

Snæbjørn


3 Answers

The difference is on Server Pagging Driven Mode

OData provide two modes of server-pagging: 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 pagging. 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 pagging. Reponse 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

like image 95
Pagotti Avatar answered Oct 27 '22 19:10

Pagotti


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.

like image 32
Sam Xu Avatar answered Oct 27 '22 21:10

Sam Xu


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.

like image 34
jvitor83 Avatar answered Oct 27 '22 19:10

jvitor83