SQL Server 2008 的 EntityFramework(使用 LINQ)中基于偏移/获取的分页(实现)
我使用的是 SQL Server 2008 和实体框架 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);
相关文章