.NET Core EF Framework uses SQL server 2008 database paging problem: Incorrect syntax near 'OFFSET' Invalid usage of the option NEXT in the FETCH statement.

First, the problem

Recently .Net Core deployed to the server, using EF6. Local database is SQL server 2016, the database server is installed SQL server 2008 R2, when used in the paging query given as follows:

{
  "Depth": 0,
  "ClassName": "",
  "Message": "Incorrect syntax near 'OFFSET'.\r\nInvalid usage of the option NEXT in the FETCH statement.",
  "Source": "Core .Net SqlClient Data Provider",
}

Second, the cause

The problem can be described by analyzing a database SQL server 2008 R2 version of SQL statement does not support keyword OFFSET, NEXT, because these two key new features of SQL server is beyond 2012.

If you see this text, indicating that you are using an RSS reader or switched from "a tree - blog Park", the original address: https://www.cnblogs.com/atree/p/netcroe-EF-SQL-Server- OFFSET-NEXT-pAGE.html

Third, the solution

By configuring .UseRowNumberForPaging () that is configured with the paging row number SQL keywords. In Startup.cs, add the following code:

public void ConfigureServices(IServiceCollection services) 
{ services.AddDbContext
<ATreeContext> (options => options.UseSqlServer(_config["ConnectionStrings:DefaultConnection"], p => p.UseRowNumberForPaging ())); }

 

Guess you like

Origin www.cnblogs.com/atree/p/netcroe-EF-SQL-Server-OFFSET-NEXT-PAGE.html