【发布时间】:2010-10-24 22:48:33
【问题描述】:
我想在我的存储库之外进行分页,但存储库返回 IList。由于我不想不必要地拉取数据,也不想在我的 Repositories 中创建特定的 Paging 方法,有没有办法在 Where 扩展方法中按页面过滤记录?
我想做这样的事情:
var myRecords = ProductRepo.Get( p => p.Name.StartsWith("Pepsi") &&
p.Row_Number() > 9 &&
p.Row_Number() < 21);
获取存储库代码(当然不处理行号):
public IList<Product> Get( Expression<Func<Product, bool>> filter = null)
{
if( filter == null)
return _dc.Products.ToList<Product>();
else
return _dc.Products.Where(filter).ToList<Product>();
}
【问题讨论】:
-
能否提供
ProductRepo.Get的实现? -
显然,这只能在不从存储库返回 Collection 类型或在存储库中执行 Skip and Take 的情况下完成。我想知道为什么你不能在代表 ROW_NUMBER OVER (ORDER BY) 的 SQL 中创建一个字段。我会继续寻找。
标签: c# entity-framework-4 repository-pattern