Server side paging is a very important aspect of designing and implementing your OData Data API. As a best practice I always stress when designing your Data API using the OData protocol to be very careful and use a good PageSize setting so that a query will not congest valuable server resources while also allowing great user experience (UX) on the consuming application side.

Recently I was asked if there was a way to configure a default PageSize across all entity sets in ASP.NET Web API OData. After discussing this with the OData team, I wanted to let people know that by adding an AddODataQueryFilter you can configure a starting PageSize. This global setting can be overridden by a more specific setting on controller or action for Entities that need a custom PageSize. The following is an example for configuring a PageSize of 100 for all entity query results.

config.AddODataQueryFilter(new EnableQueryAttribute { PageSize = 100 });

The code above would be added to the Register() method of the project’s WebApiConfig.cs file.

2 thoughts on “How to have a default PageSize across all Entity Queries in your OData Data API

  1. Hi

    Is there anyway to have this default page size but the end client can still override it as part of the odata querystring parameters?

    As we like the idea of the default page size but our clients would also like to retrieve the entire result set in one call.

    ie ?$odata.MaxPageSize=0


    1. At this time that is not possible. You would have to build the maximum page size into your client calls. Could be possible if you had AuthZ/AuthN built into your OData endpoint so you had more control over who could call it.

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.