c# - Skip and Take 在 Entity Framework 中生成异常

标签 c# sql .net entity-framework linq

在执行以下查询时,我在 InnerException 中收到错误

{"Incorrect syntax near 'OFFSET'. Invalid usage of the option NEXT in the FETCH statement. Incorrect syntax near the keyword 'AS'. Incorrect syntax near 'OFFSET'. Invalid usage of the option NEXT in the FETCH statement. Incorrect syntax near the keyword 'AS'. Incorrect syntax near 'OFFSET'. Invalid usage of the option NEXT in the FETCH statement. Incorrect syntax near the keyword 'AS'."}

C#代码:

var db = new DigilibEntities();

List<title> titles = new List<title>();

titles = db.titles
  .Include("themes")
  .Include("subjects")
  .Include("grades")
  .Where(x => x.themes.Count() == 0 || 
              x.subjects.Count() == 0 || 
              x.grades.Count() == 0)
  .OrderBy(x => x.id)
  .Skip(10)
  .Take(10)
  .ToList();

最佳答案

默认情况下,EF 将使用 FETCH 和 OFFSET 语法进行分页。旧版本的 SQL Server 不支持此语法。您需要将 ProviderManifestToken 设置为 2008,以便 EF 生成旧的 2008 风格语法。

A breaking change in Entity Framework 6.1.2 when using EDMX and SQL Server 2008/2005

关于c# - Skip and Take 在 Entity Framework 中生成异常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43322641/

相关文章:

c# - 在c#.net中的Array.indexof中使用正则表达式查找元素的索引

c# - 错误的使用?运算符[重复项]

c# - 按名称访问 ResourceDictionary

c# - 责任链设计模式有哪些替代方案?

c# - 如何在 C# 中更新查询字符串?

php - 没有找到数据库!! mysql错误

SQL Server 2005的: Converting varchar value '1.23E-4' to decimal fails

c# - 哪个控件可以构建一个十六进制编辑器?

c# - 归档 zip 文件并将其保存到选择的位置,而不需要额外的文件路径?

MYSQL 从每个类别中选择一个随机记录