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

查看:31
本文介绍了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);

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

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