我正在从这里尝试 PagedList.Mvc 库
https://github.com/TroyGoode/PagedList
有这个用法示例
var products = MyProductDataSource.FindAllProducts(); //returns IQueryable<Product> representing an unknown number of products. a thousand maybe?
var pageNumber = page ?? 1; // if no page was specified in the querystring, default to the first page (1)
var onePageOfProducts = products.ToPagedList(pageNumber, 25); // will only contain 25 products max because of the pageSize
MyProductDataSource.FindAllProducts() 的典型实现;是沿着
public IQuerable<T> MyProductDataSource.FindAllProducts()
{
using ( var ctx = new MyCtx() )
{
return ctx.MyList().Where( .... );
}
}
这当然有 InvalidOperationException() 和 DBContext is already dispose 消息
寻找关于如何返回 IQueryable 的最佳实践,可以在这里毫无问题地使用?