OFFSET' 附近有語法錯誤。 在 FETCH 語句中選項 NEXT 的用法無效


OFFSET' 附近有語法錯誤。 在 FETCH 語句中選項 NEXT 的用法無效。
最近在使用asp.net core的時候,采用take().skip()分頁的時候報以下錯誤:
SqlException: 'OFFSET' 附近有語法錯誤。 在 FETCH 語句中選項 NEXT 的用法無效。
這個主要是在sql server 2008中,不支持FETCH和NEXT語句(sql server 2012才支持)。
以后在網上參考了一下其余的文章,最終解決了這個問題,記錄一下,方便后來人。
解決方法:
修改“StartUp.cs”文件,具體代碼截圖以下:
1.普通修改方式
// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
// Add framework services.
services.AddMvc();
 
var connection = @"Data Source=tcp:111.111.111.111,1044;
Initial Catalog=xxx;Persist Security Info=True;User ID=xxxx;Password=xxxxx";
services.AddDbContext<NoteContext>(options => options.UseSqlServer(connection, b=>b.UseRowNumberForPaging()));
 
services.AddScoped<Repository.INoteRepository,Repository.NoteRepository>();
services.AddScoped<Repository.INoteTypeRepository, Repository.NoteTypeRepository>();
}
 
2.abp修改方式
public static class DbContextOptionsConfigurer
{
public static void Configure(
DbContextOptionsBuilder<SSODbContext> dbContextOptions,
string connectionString
)
{
/* This is the single point to configure DbContextOptions for testDbContext */
dbContextOptions.UseSqlServer(connectionString , b => b.UseRowNumberForPaging());
}
}


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM