Udostępnij za pośrednictwem


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

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 (WCF Data Services).

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

Tasks

How to: Load Paged Results (WCF Data Services)

Concepts

Loading Deferred Content (WCF Data Services)