2011-01-06 38 views
2

问题:重用我PagedList对象WCF

我有一个自定义集合PagedList<T>正从我的WCF服务返回PagedListOfEntitySearchResultW_SH0Zpu5当T EntitySearchResult对象。

我想在应用程序和服务之间重用这种PagedList<T>类型。

我的情景:

我创建了一个PagedList<T>类型从List<T>继承。 此类型位于应用程序和WCF服务中引用的分离程序集上。

我正在使用scvutil上的/ reference选项来启用类型重用。我也不希望任何数组返回,因此我也使用/collection映射到通用List类型。 我使用下面的命令svcutil生成服务代理:

"C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\Bin\NETFX 4.0 Tools\svcutil.exe" 
/collectionType:System.Collections.Generic.List`1 
/reference:..\..\bin\Debug\App.Utilities.dll 
http://localhost/App.MyService/MyService.svc?wsdl 
/namespace:*,"App.ServiceReferences.MyService" 
/out:..\ServiceProxy\MyService.cs 

的PagedList对象是一样的东西:

[CollectionDataContract] 
public partial class PagedList<T> : List<T> 
{ 

    public PagedList() { } 

    /// <summary> 
    /// Creates a new instance of the PagedList object and doesn't apply any pagination algorithm. 
    /// The only calculated property is the TotalPages, everything else needed must be passed to the object. 
    /// </summary> 
    /// <param name="source"></param> 
    /// <param name="pageNumber"></param> 
    /// <param name="pageSize"></param> 
    /// <param name="totalRecords"></param> 
    public PagedList(IEnumerable<T> source, int pageNumber, int pageSize, int totalRecords) 
    { 
    if (source == null) 
    source = new List<T>(); 

    this.AddRange(source); 

    PagingInfo.PageNumber = pageNumber; 
    PageSize = pageSize; 
    TotalRecords = totalRecords; 
    } 

    public PagedList(IEnumerable<T> source, PagingInfo paging) 
    { 
    this.AddRange(source); 
    this._pagingInfo = paging; 
    } 

    [DataMember] 
    public int TotalRecords { get; set; } 

    [DataMember] 
    public int PageSize { get; set; } 

    public int TotalPages() 
    { 
    if (this.TotalRecords > 0 && PageSize > 0) 
    return (int)Math.Ceiling((double)TotalRecords/(double)PageSize); 
    else 
    return 0; 
    } 

    public bool? HasPreviousPage() 
    { 
    return (PagingInfo.PageNumber > 1); 
    } 

    public bool? HasNextPage() { return (PagingInfo.PageNumber < TotalPages()); } 

    public bool? IsFirstPage() { return PagingInfo.PageNumber == 1; } 

    public bool? IsLastPage() { return PagingInfo.PageNumber == TotalPages(); } 

    PagingInfo _pagingInfo = null; 
    [DataMember] 
    public PagingInfo PagingInfo 
    { 
    get { 
    if (_pagingInfo == null) 
    _pagingInfo = new PagingInfo(); 

    return _pagingInfo; 
    } 
    set 
    { 
    _pagingInfo = value; 
    } 
    } 
} 
+0

所以问题真的是?!?!?..... – 2011-01-06 15:52:22

回答

1

我想我知道这里发生了什么...
/collection与这种情况下的/reference冲突,因为我的PagedList对象继承自List<T>。 我刚刚将/ collection更改为以下版本,现在可以使用。

/collectionType:App.Utilities.Data.PagedList`1 

事情是,我所有的收藏将检索为PagedList。
这对我来说并不是一个问题,但需要能够在需要时默认检索List<T>,并在需要时检索PagedList<T>