我工作的项目有实体框架上的OData层的顶部。 Odata图层将其服务器端分页转换为值为75
。我对这个主题的阅读使我相信,这个分页值是全面使用的,而不是每个表的基础。我目前希望从提取所有数据表,当然,超过75行。使用实体框架,我的代码只是这样的:实体框架+ ODATA:侧步执行分页
public IQueryable<ProductColor> GetProductColors()
{
return db.ProductColors;
}
其中db
是实体环境。这是返回前75个记录。我读的东西在那里我可以一个参数inlinecount
集追加到allpages
给我下面的代码:
public IQueryable<ProductColor> GetProductColors()
{
return db.ProductColors.AddQueryOption("inlinecount","allpages");
}
然而,这也将返回75行!
谁能阐明了如何真正得到所有的记录,而不管的的OData服务器端分页的东西?
重要:我无法删除分页或将其关闭!在性能受到关注的其他情况下,它非常有价值。
更新: 通过一些搜索我发现一个MSDN描述如何执行此任务。
我很想能够把它变成一个完整的通用方法,但是,这是亲如我能得到一个通用的,而无需使用反射:
public IQueryable<T> TakeAll<T>(QueryOperationResponse<T> qor)
{
var collection = new List<T>();
DataServiceQueryContinuation<T> next = null;
QueryOperationResponse<T> response = qor;
do
{
if (next != null)
{
response = db.Execute<T>(next) as QueryOperationResponse<T>;
}
foreach (var elem in response)
{
collection.Add(elem);
}
} while ((next = response.GetContinuation()) != null);
return collection.AsQueryable();
}
调用它像:
public IQueryable<ProductColor> GetProductColors()
{
QueryOperationResponse<ProductColor> response = db.ProductColors.Execute() as QueryOperationResponse<ProductColor>;
var productColors = this.TakeAll<ProductColor>(response);
return productColors.AsQueryable();
}