Offset/Fetch based paging (Implementation) in EntityFramework (Using LINQ) for SQL Server 2008

entity-framework entity-framework-6 pagination sql-server sql-server-2008

Question

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().

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

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

1
2
7/25/2017 12:07:33 PM

Accepted Answer

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

Do this:

var results = context.MyTable
    .Skip(() => 10)
    .Take(() => 5);
7
7/25/2017 12:26:37 PM

Popular Answer

The fix is to modify your EDMX file, using the XML editor, and change the value of ProviderManifestToken from 2012 to 2008. I found that on line 7 in my EDMX file. After saving that change, the paging SQL will be generated using the “old”, SQL Server 2008 compatible syntax.



Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow