Getting invalid syntax next to "OFFSET" error in NHibernate.Linq query

I am getting the following error in my application ASP.NET MVC 4.0

with NHibernate v4.0.0 (.Net Framework 4.0)

. This error is displayed in the NHibernate.Linq

request

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 found several similar posts on SO and other sites. but they suggest to use SQL SERVER 2012 instead of 2008. Yes, my version is sql server 2008

. but i created another app using ASP.NET MVC 5 (.Net Framework 4.5)

and NHibernate v3.3.1

and it works fine on the same database and same sql server version.

Some related posts:

So, I don't think the problem is with my version of SQL Server, at least in my case.

I am not executing sql query directly in ssms or via command object. I am using NHibernate.Linq

query.

Full NHibernate query:

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

      

How to solve this problem. Please guide me.

Please ask me if this is not enough.

Thank!

+3


source to share


1 answer


It seems like NHibernate is just mistakenly instructed to use a dialect related to SQL Serer 2012

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

      

Just install it in 2008



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

      

and it will not use functions from the later version Implement swap functions (skip / take) with this request

+7


source







All Articles