SQL Server 2008的EntityFramework(使用LINQ)中基于偏移/获取的分页(实现) [英] Offset/Fetch based paging (Implementation) in EntityFramework (Using LINQ) for SQL Server 2008

查看:281
本文介绍了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 Server2012.对于我来说,这不是一个选择.

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

推荐答案

使用实体框架6.1,这是可能的. 2 及更高版本,因此您可以在项目中使用它.标准的Skip和Take方法无法与其他方法一样捕获.现在有两个额外的Skip/Take方法重载,需要lambda,所以代替这个:

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);

这篇关于SQL Server 2008的EntityFramework(使用LINQ)中基于偏移/获取的分页(实现)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆