How to: Enable Paging of Data Service Results (WCF Data Services)

Important

WCF Data Services has been deprecated and will no longer be available for download from the Microsoft Download Center. WCF Data Services supported earlier versions of the Microsoft OData (V1-V3) protocol only and has not been under active development. OData V1-V3 has been superseded by OData V4, which is an industry standard published by OASIS and ratified by ISO. OData V4 is supported through the OData V4 compliant core libraries available at Microsoft.OData.Core. Support documentation is available at OData.Net, and the OData V4 service libraries are available at Microsoft.AspNetCore.OData.

RESTier is the successor to WCF Data Services. RESTier helps you bootstrap a standardized, queryable, HTTP-based REST interface in minutes. Like WCF Data Services before it, Restier provides simple and straightforward ways to shape queries and intercept submissions before and after they hit the database. And like Web API + OData, you still have the flexibility to add your own custom queries and actions with techniques you're already familiar with.

WCF Data Services enables you to limit the number of entities returned by a data service query. Page limits are defined in the method that is called when the service is initialized and can be set separately for each entity set.

When paging is enabled, the final entry in the feed contains a link to the next page of data. For more information, see Configuring the Data Service.

This topic shows how to modify a data service to enable paging of returned Customers and Orders entity sets. The example in this topic uses the Northwind sample data service. This service is created when you complete the WCF Data Services quickstart.

How to enable paging of returned Customers and Orders entity sets

  • In the code for the data service, replace the placeholder code in the InitializeService function with the following:

    // Set page size defaults for the data service.
    config.SetEntitySetPageSize("Orders", 20);
    config.SetEntitySetPageSize("Order_Details", 50);
    config.SetEntitySetPageSize("Products", 50);
    
    // Paging requires v2 of the OData protocol.
    config.DataServiceBehavior.MaxProtocolVersion =
        System.Data.Services.Common.DataServiceProtocolVersion.V2;
    
    ' Set page size defaults for the data service.
    config.SetEntitySetPageSize("Orders", 20)
    config.SetEntitySetPageSize("Order_Details", 50)
    config.SetEntitySetPageSize("Products", 50)
    
    ' Paging requires v2 of the OData protocol.
    config.DataServiceBehavior.MaxProtocolVersion = _
        System.Data.Services.Common.DataServiceProtocolVersion.V2
    

See also