在NHibernate中获取不正确的语法,接近“偏移”错误。Linq查询

时间:2021-10-17 02:18:17

I am getting following error in my ASP.NET MVC 4.0 Application with NHibernate v4.0.0 (.Net Framework 4.0). This error shows in NHibernate.Linq query

我在ASP中有以下错误。使用NHibernate v4.0.0(。净框架4.0)。这个错误显示在NHibernate中。Linq查询

Incorrect syntax near 'OFFSET'.
Invalid usage of the option FIRST in the FETCH statement.

IN THIS LINE

在这条线

Line 23:         public IList<Post> Posts(int pageNo, int pageSize)
Line 24:         {
Line 25:             var posts = _session.Query<Post>()  //here
Line 26:                                   .Where(p => p.Published) 
Line 27:                                   .Skip(pageNo * pageSize)

I have found some similar posts on SO and on other sites. but, they are suggesting that use SQL SERVER 2012 instead of 2008. Yes my sql server version is 2008. but, I have created another application using ASP.NET MVC 5 (.Net Framework 4.5) and NHibernate v3.3.1 and it works great in same database and same sql server version.

我在SO和其他网站上找到了一些类似的帖子。但是,他们建议使用SQL SERVER 2012而不是2008。是的,我的sql server版本是2008。但是,我使用ASP创建了另一个应用程序。5(净MVC。Net Framework 4.5和NHibernate v3.3.1在相同的数据库和相同的sql server版本中运行良好。

Some similar post:

一些类似的文章:

  1. “Incorrect syntax near 'OFFSET'” modift sql comm 2012 to 2008
  2. “不正确的语法”,接近“偏移”的sql comm 2012到2008。
  3. Pagination query for mssql server 2008 Throwing Incorrect syntax near 'OFFSET'
  4. mssql服务器2008的分页查询,抛出不正确的语法,接近“偏移”
  5. Making sense of 'OFFSET/FETCH' in SSMS 2012
  6. 2012年SSMS的“偏移/获取”意义。

So, I don't think that the problem is in my sql server version at least in my case.

所以,我不认为这个问题在我的sql server版本中至少在我的例子中。

I am not executing sql query directly into ssms or through command object. I am using NHibernate.Linq query.

我不是直接执行sql查询到ssm或通过命令对象。我使用NHibernate。Linq查询。

Full NHibernate Query:

完整的NHibernate查询:

 var posts = _session.Query<Post>()
                              .Where(p => p.Published)
                              .Skip(pageNo * pageSize)
                              .Take(pageSize)
                              .Fetch(p => p.Category)
                              .ToList();

How do I solve this problem. Please guide me.

我该如何解决这个问题呢?请指导我。

Please ask me for more information if it is insufficient.

如果不够的话,请向我询问更多的信息。

Thanks !!

谢谢! !

1 个解决方案

#1


7  

It seems, that NHibernate is just wrongly instructed to use dialect related to SQL Serer 2012

看起来,NHibernate被错误地指示使用与SQL Serer 2012相关的方言。

<property name="dialect">NHibernate.Dialect.MsSql2012Dialect</property>

Just set it to 2008

把它设置到2008年。

<property name="dialect">NHibernate.Dialect.MsSql2008Dialect</property>

and it will NOT use features from a later version Implement paging (skip / take) functionality with this query

而且它不会使用稍后版本的特性来实现这个查询的分页(跳过/获取)功能。

#1


7  

It seems, that NHibernate is just wrongly instructed to use dialect related to SQL Serer 2012

看起来,NHibernate被错误地指示使用与SQL Serer 2012相关的方言。

<property name="dialect">NHibernate.Dialect.MsSql2012Dialect</property>

Just set it to 2008

把它设置到2008年。

<property name="dialect">NHibernate.Dialect.MsSql2008Dialect</property>

and it will NOT use features from a later version Implement paging (skip / take) functionality with this query

而且它不会使用稍后版本的特性来实现这个查询的分页(跳过/获取)功能。