【发布时间】:2012-03-01 15:45:48
【问题描述】:
有没有人知道如何使用 DbContext 来执行服务器端分页和 orderby 功能。我使用 Where 子句过滤记录。需要类似的东西,以便我只能获得有限数量的记录。
提前致谢
【问题讨论】:
-
嗨,我的存储库中没有可用的 MyDbContext。怎么办?
标签: c# asp.net-mvc-3 entity-framework-4.1
有没有人知道如何使用 DbContext 来执行服务器端分页和 orderby 功能。我使用 Where 子句过滤记录。需要类似的东西,以便我只能获得有限数量的记录。
提前致谢
【问题讨论】:
标签: c# asp.net-mvc-3 entity-framework-4.1
检查此解决方案。可能是您正在寻找的:
public const int PAGE_SIZE = 10;
protected void LinqDataSource1_Selecting(object sender, LinqDataSourceSelectEventArgs e)
{
// LINQ query
var query = from m in db.Products
select m;
// Set the total count
// so GridView knows how many pages to create
e.Arguments.TotalRowCount = query.Count();
// Get only the rows we need for the page requested
query = query.Skip(GridView1.PageIndex * PAGE_SIZE).Take(PAGE_SIZE);
e.Result = query;
}
【讨论】:
【讨论】:
code IQueryablecode