我认为,无论有10条记录还是1千万条记录,以下内容都有效。是否有像这样的linq等效项?
class Program
{
static void Main(string[] args)
{
using (var ctx = new pubsEntities())
{
//this will throw an exception
var studentName = ctx.Database.SqlQuery<employee>(@"
;with CTE AS
(
SELECT *, ROW_NUMBER() over(order by emp_id) AS RowNumber
FROM employee
)
SELECT * FROM CTE
WHERE RowNumber > 2 AND RowNumber <= (2 + 4)
").ToList();
}
}
}
答案 0 :(得分:1)
您可以使用IQueryable<T>.Skip(x).Take(x)
模拟分页。
非常简单。如果我们正在查看您的代码,则需要这样的东西:
var pageSize = 100;
var startPage = 2;
var skipAmount = pageSize * startPage;
ctx.Database.Employee.Skip(skipAmount).Take(pageSize);