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.

abatishchev
  • 98,240
  • 88
  • 296
  • 433
Snæbjørn
  • 10,322
  • 14
  • 65
  • 124

3 Answers3

5

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

Pagotti
  • 222
  • 3
  • 10
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.

Sam Xu
  • 3,264
  • 1
  • 12
  • 17
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.

jvitor83
  • 220
  • 8
  • 20