SQL Server 2008 EntityFramework(使用 LINQ)中基于偏移/获取的分页(实现)

我正在使用 SQL Server 2008 和 Entity Framework 6.1.3.我希望基于 OFFSET/FETCH 而不是 Take() &跳过().

I am using SQL Server 2008 and Entity Framework 6.1.3. I wish to implement pagination of data based on OFFSET/FETCH rather than Take() & Skip().

我在网上搜索没有运气.一些帖子建议迁移到 SQL Server 2012.在我的情况下,这不是一个选项.

I searched online with no luck. Some posts suggested migrating to SQL Server 2012. Which is not an option in my case.

有人可以建议如何在 SQL Server 2008 和 EF 6.1.3 中使用 OFFSET/FETCH

Can someone suggest how to use OFFSET/FETCH with SQL Server 2008 and EF 6.1.3

推荐答案

这可以通过 Entity Framework 6.1 实现.2 及以上,所以你应该可以在你的项目中使用它.标准的 Skip 和 Take 方法无法像其他方法一样被捕获.现在有两个额外的使用 lambda 的 Skip/Take 方法重载,所以不要这样:

This is possible with Entity Framework 6.1.2 and above so you should be OK to use it in your project. The standard Skip and Take methods can't be captured in the same way as others. There are now two additional overload of the Skip/Take methods that take lambdas, so instead of this:

var results = context.MyTable
    .Skip(10)
    .Take(5);

这样做:

var results = context.MyTable
    .Skip(() => 10)
    .Take(() => 5);

相关文章