Implementing pager through WCF service

后端 未结 1 846
野趣味
野趣味 2020-12-14 04:01

I am developing an application which includes a WCF service and its ASP.NET MVC client. The ASP.NET MVC website must display a grid of objects - say, products. These product

相关标签:
1条回答
  • 2020-12-14 04:51

    What is your back-end database layer look like? If you're using LINQ (-to-SQL or -to-Entities), you could implement paging through WCF by specifying the page size and the page number you want, and then use LINQ's "Skip" and "Take" operators to fetch the page requested - something roughly like:

    [ServiceContract]
    public interface IFetchData
    {
      [OperationContract]
      public List<Data> GetData(int pageSize, int pageNumber)
    }
    

    and then implement it something like this (simplified):

    public class FetchDataService : IFetchData
    {
      public List<Data> GetData(int pageSize, int pageNumber)
      {
          var query = yourContext.DataTable
                        .Skip((pageNumber - 1) * pageSize)
                        .Take(pageSize);
    
          return query.ToList();
      }
    }
    

    Would that be helpful for you??

    Marc

    0 讨论(0)
提交回复
热议问题