有没有人可以告诉如何使用DbContext做服务器端分页和orderby功能。我用Where子句来过滤记录。需要类似的东西,以便我只能得到有限数量的记录。服务器端分页和OrderBy与DbContext
在此先感谢
有没有人可以告诉如何使用DbContext做服务器端分页和orderby功能。我用Where子句来过滤记录。需要类似的东西,以便我只能得到有限数量的记录。服务器端分页和OrderBy与DbContext
在此先感谢
这就是我想要做 'code' 的IQueryable
检查此解决方案。可能是它你要找的东西:
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;
}
虽然这可能在理论上回答这个问题,这将是更好的](http://meta.stackexchange.com/q/8259)在这里包括答案的基本部分,并提供链接供参考。 – Taryn 2013-03-05 14:06:22
退房http://stackoverflow.com/questions/3870091/entity-framework-linq-to-sql-skip-take – Matthew 2012-03-01 15:48:42
喜,我的仓库中没有MyDbContext。如何去做呢? – afr0 2012-03-01 16:03:49