我以前用code first 数据库是 SQL SERVER 2012 ,程序完全正常,数据库换成 SQL SERVER 2008 R2 就不行了,报如下错误
'OFFSET' 附近有语法错误。\r\n在 FETCH 语句中选项 NEXT 的用法无效。
.net MVC
I encountered this problem myself using EF 7 and sql server 2008. Fortunately in the latest rc1 version of EF 7 you can solve this by using .UseRowNumberForPaging() as shown in this example:
1 2 3 4 5 6 7 8 9 |
services.AddEntityFramework() .AddSqlServer() .AddDbContext<YourDbContext>(options => options.UseSqlServer(configuration["Data:DefaultConnection:ConnectionString"]) // this is needed unless you are on mssql 2012 or higher .UseRowNumberForPaging() ); |
.net core 分页使用sql 2012分页没问题,如果用2008就出现错误了,原来是2012才支持fetch分页,解决办法如下:
在startup.cs里找到配置选项,参考如下:注意红色部分
services.AddDbContext<MailBoxDbcontext>(options=>options.UseSqlServer(Configuration.GetConnectionString("MailBoxDbcontext"),x=>x.UseRowNumberForPaging(true)));
发表评论