【发布时间】: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();
}
【问题讨论】: