WCF Data Service - How to set Page Size programmatically?

戏子无情 提交于 2019-12-12 23:06:39

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!