【问题标题】:Combining the use of Skip Tokens and Server-Side Filtering in WCF Data Services v2在 WCF 数据服务 v2 中结合使用跳过令牌和服务器端过滤
【发布时间】:2014-04-08 13:03:40
【问题描述】:

如何在 WCF 数据服务(第 2 版)中结合使用过滤和服务器端分页?

在下面的代码 sn-p 中,NextLinkUri 总是缺少 $filter 查询参数。我已经尝试使用 NextLinkUri 构建一个新的 Uri 并重新添加 $filter 参数并改为执行这个新的 Uri。毫不奇怪,这会导致服务器端错误。

var query3 = ServiceContext.ConventionalReturnFacts;
var filterString = String.Format("CalendarDateId ge {0} and CalendarDateId lt {1}",
                    passedCalendarYear * 10000,
                    (passedCalendarYear + calendarYearIncrement) * 10000);
query3.AddQueryOption("$filter", filterString);

// Get first page of results
var response = query3.Execute();
result.Results = response.ToList();

// Get remaining pages (if any)
var continuation = ((QueryOperationResponse)response).GetContinuation();
while (continuation != null)
{
    // NextLinkUri is missing the $filter query parameter so pages 2 and
    // up end up having unfiltered entities!
   response = ServiceContext.Execute<ConventionalReturnFact>(continuation.NextLinkUri);        
   ((List<ConventionalReturnFact>)result.Results).AddRange(response.ToList());
   continuation = ((QueryOperationResponse)response).GetContinuation();
}

【问题讨论】:

    标签: wcf-data-services


    【解决方案1】:

    客户端不应将任何系统查询选项附加到下一个链接的 URL。下一个链接对客户端是不透明的。

    在您的情况下,下一个链接应返回过滤数据的下一页。如果不是,那是服务的问题,而不是客户端的问题。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-02-21
      • 2011-12-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多