'OFFSET' 附近的语法不正确.FETCH 语句“in Entity Framework core"中选项 NEXT 的使用无效; [英] Incorrect syntax near 'OFFSET'. Invalid usage of the option NEXT in the FETCH statement "in Entity Framework core"
本文介绍了'OFFSET' 附近的语法不正确.FETCH 语句“in Entity Framework core"中选项 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());
}
或者作为启动的一部分:
Or as a part of the Startup:
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 语句“in Entity Framework core"中选项 NEXT 的使用无效;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文