Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
981 views
in Technique[技术] by (71.8m points)

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

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...