通过WCF服务实现寻呼机 [英] Implementing pager through WCF service

查看:92
本文介绍了通过WCF服务实现寻呼机的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我开发的应用程序,其中包括一个WCF服务和ASP.NET MVC客户端。在ASP.NET MVC网站必须显示对象的网格 - 比如,产品。这些产品被存储在数据库中这是通过WCF服务访问。所以某处一个MVC控制器我打电话WCF服务的方法,返回我的,我展示产品需要一个数组中。

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 products are stored in database which is accessible through the WCF service. So somewhere inside an MVC controller I call WCF service's method that returns me an array of products that I need to display.

那么,什么是我的问题吗?我要实现我的产品网寻呼机的功能,因为它有可能会有很多的产品。因此,有几种方法可以做到这一点:

So what is my question? I want to implement a pager functionality for my products grid, because it is possible that there will be a lot of products. So there are several ways to do that:


  1. 我的控制器可以得到产品的整个列表,只是做内存分页

  2. WCF可以选择所有的产品和它们在其高速缓存某处存储,然后传递到控制器只是其中的一部分,根据所请求的页号。

  3. WCF可以根据请求的页号从数据库中选择的产品的一部分。

  4. WCF可以返回的IQueryable到控制器,然后控制器将选择任何他想做的,每当他想要的。

据我了解(和纠正我,如果它是不是真的),第一个选项是没用的,所以我必须在别人之间选择。

As far as I understand (and correct me if it is not true), the first option is useless, so I must choose between the others.

第二个选择浪费我的服务器的内存中。

The second option wastes my server's memory.

第三个选项是确定的,但似乎有点难看实现在WCF端分页。

The third option is OK, but it seems a little bit ugly to implement paging on the WCF side.

和第四个选项听起来有点混乱。其实,我通过一些类型的查询到客户端,然后他亲自查询我的数据库,通过WCF服务。我无法弄清楚如何正确地实现这一点。

And the fourth option sounds confusing. I actually pass some kind of query to the client, and then he queries my database by himself, through the WCF service. I can't figure out how to implement this correctly.

所以,可以请你帮我选择实现这个正确的方法是什么?

So can you please help me to choose the correct way to implement this?

推荐答案

你是什么后端数据库层是什么样子?如果你使用LINQ(-to-SQL或-to-实体),你可以通过指定页面大小和所需的页面数通过实现分页WCF,然后使用LINQ的跳过和Take经营者获取请求的页面 - 这大致是:

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??

马克

这篇关于通过WCF服务实现寻呼机的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆