C# 靠近'的语法不正确;偏移量';。FETCH语句中NEXT选项的使用无效;在实体框架核心中”;

C# 靠近'的语法不正确;偏移量';。FETCH语句中NEXT选项的使用无效;在实体框架核心中”;,c#,asp.net,sql-server-2008,asp.net-core,entity-framework-core,C#,Asp.net,Sql Server 2008,Asp.net Core,Entity Framework Core,以下是我的EF核心代码: int page = 1, rowPerPage = 5; int count = ctx.Specialty.Count(); int start = page * rowPerPage; var Select = ctx.Specialty.OrderByDescending(u => u.IdS) .Skip(start) .Take(rowPerPage) .AsEnumer

以下是我的EF核心代码:

 int page = 1, rowPerPage = 5;
 int count = ctx.Specialty.Count();
 int start = page * rowPerPage;

 var Select = ctx.Specialty.OrderByDescending(u => u.IdS)
            .Skip(start)
            .Take(rowPerPage)
            .AsEnumerable();
错误

public class AppDbContext : DbContext
{

    protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
    {
        var coonectionString = "Data Source=localhost\\MSSQLSERVER01;Initial Catalog=AppDb01;Integrated Security=True";
        optionsBuilder.UseSqlServer(coonectionString);
    }
}
靠近“OFFSET”的语法不正确。FETCH语句中NEXT选项的使用无效


我的查询不支持sql server 2008

解决方案

public class AppDbContext : DbContext
{

    protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
    {
        var coonectionString = "Data Source=localhost\\MSSQLSERVER01;Initial Catalog=AppDb01;Integrated Security=True";
        optionsBuilder.UseSqlServer(coonectionString);
    }
}
到目标服务器的值连接字符串
并插入设置,示例代码采用默认的ASP NET Core项目格式。

对此有一个兼容性设置(
UseRowNumberForPaging
),可以在DbContext本身中进行配置:

    protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
    {
        var coonectionString = "Data Source=localhost\\MSSQLSERVER01;Initial Catalog=AppDb01;Integrated Security=True";
        optionsBuilder.UseSqlServer(coonectionString, builder => builder.UseRowNumberForPaging());
    }
或者作为启动的一部分:

    public void ConfigureServices(IServiceCollection services)
    {
        var coonectionString = "Data Source=localhost\\MSSQLSERVER01;Initial Catalog=AppDb01;Integrated Security=True";
        services.AddDbContext<AppDbContext>(options => options.UseSqlServer(coonectionString, builder => builder.UseRowNumberForPaging()));
    }
public void配置服务(IServiceCollection服务)
{
var coonnectionstring=“数据源=localhost\\MSSQLSERVER01;初始目录=AppDb01;集成安全性=True”;
services.AddDbContext(options=>options.UseSqlServer(coonnectionstring,builder=>builder.UseRowNumberForPaging());
}

UseRowNumberForPaging
在EF Core 3.x中,方法被标记为过时。但是,您可以使用
EfCore3.SqlServer2008Query
包。Nuget中有两个可用的软件包,一个用于>=.NET 5.0,另一个用于>=.NET Core 3.1

用法:

 services.AddDbContext<MyDbContext>(o => 
       o.UseSqlServer(Configuration.GetConnectionString("Default"))
        .ReplaceService<IQueryTranslationPostprocessorFactory, SqlServer2008QueryTranslationPostprocessorFactory>());
services.AddDbContext(o=>
o、 UseSqlServer(Configuration.GetConnectionString(“默认”))
.ReplaceService());

您是连接到SQL 2008数据库还是SQL 2017数据库(检查连接字符串)?@mjwills SQL 2008您需要更改连接字符串以指向SQL 2017数据库。如果您的系统上有SQL Server 2008和2017,其中至少有一个必须使用显式实例名称-只需使用连接字符串连接到该SQL Server实例即可。您知道在哪里可以获取该nuget的源代码吗?