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.
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.
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
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
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
.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With