问题
I have an OData Service setup using WCF Data Services (v2) that is hosted on the server. In the client applications we are creating, we are wondering if there is any way we can programmatically set the paging size?
For example, this works if I set it in the .svc:
public static void InitializeService(ODataServiceConfiguration serviceConfig)
{
serviceConfig.SetServiceOperationAccessRule("*", ServiceOperationRights.All);
serviceConfig.SetEntitySetAccessRule("*", EntitySetRights.All);
// *** I would like to set the following in my client code
serviceConfig.SetEntitySetPageSize("Employees", 100);
...
Any advice will be appreciated.
回答1:
Server paging is defined only on the server but you can use Take
and Skip
methods for client paging directly in your query.
var data = (from e in context.Entities
select e).Skip(200).Take(100);
This example will skip 200 entities in result set and return entity 201 to 300. If you have 100 entities per page it is like selecting third page.
来源:https://stackoverflow.com/questions/8146631/wcf-data-service-how-to-set-page-size-programmatically