本文介绍了'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();

错误:

推荐答案

对此有一个兼容性设置(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.的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

06-12 02:36