Stuart.Sklinar
Stuart.Sklinar

Reputation: 3761

Nhibernate take skip not producing correct sql

Considoring the following query:

session.Query<Brand>()
       .Where(x => x.Name == "Clause")
       .Select(a => a.Name)
       .Take(10)
       .ToList();

NHibernate is not generating the correct SQL - it does not appear to be adding the limiters and appears to be generating the take in code - not in SQL.

Any Ideas?

Generated SQL:

select brand0_.br_name as col_0_0_ from Brands brand0_
 where brand0_.br_name=?;p0 = 'Clause' 

Upvotes: 1

Views: 503

Answers (1)

Anton
Anton

Reputation: 1583

I'm using a such code and it's got "TOP" in SQL. (NHibernate version 3.1)

@mattytommo is right, you've forgot about "List()":

session.Query<Brand>()
       .Where(x => x.Name == "Clause")
       .Select(a => a.Name)
       .Take(10)
       .List();

Have you used QueryOver ?

Upvotes: 1

Related Questions