'OFFSET'附近的语法不正确.在FETCH语句“在实体框架核心"中无效使用选项NEXT. [英] Incorrect syntax near 'OFFSET'. Invalid usage of the option NEXT in the FETCH statement "in Entity Framework core"

查看:524
本文介绍了'OFFSET'附近的语法不正确.在FETCH语句“在实体框架核心"中无效使用选项NEXT.的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的EF Core代码:

Here's my EF Core code:

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

错误:

"OFFSET"附近的语法不正确. FETCH语句中选项NEXT的无效用法

推荐答案

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

There is a compatibility setting (UseRowNumberForPaging) for this which can be configured either in the DbContext itself:

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

这篇关于'OFFSET'附近的语法不正确.在FETCH语句“在实体框架核心"中无效使用选项NEXT.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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