NotSupportedException when using Skip/Take with Where clause

Description

var lst = dataContext.Linq<Member>()
.Skip(10)
.Take(10)
.Where(m => m.ID==1)
.ToList();

fails as long as the Where clause is there.

DB-Configuration is MsSqlConfiguration.MsSql2008.

-----------------------------------------------------------
System.NotSupportedException: Specified method is not supported.

at NHibernate.Hql.Ast.ANTLR.PolymorphicQuerySourceDetector.GetClassName(IASTNode querySource) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Hql\Ast\ANTLR\PolymorphicQuerySourceDetector.cs:line 61
at NHibernate.Hql.Ast.ANTLR.PolymorphicQuerySourceDetector.Process(IASTNode tree) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Hql\Ast\ANTLR\PolymorphicQuerySourceDetector.cs:line 27
at NHibernate.Hql.Ast.ANTLR.AstPolymorphicProcessor.Process() in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Hql\Ast\ANTLR\AstPolymorphicProcessor.cs:line 30
at NHibernate.Hql.Ast.ANTLR.AstPolymorphicProcessor.Process(IASTNode ast, ISessionFactoryImplementor factory) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Hql\Ast\ANTLR\AstPolymorphicProcessor.cs:line 24
at NHibernate.Hql.Ast.ANTLR.ASTQueryTranslatorFactory.CreateQueryTranslators(IASTNode ast, String queryIdentifier, String collectionRole, Boolean shallow, IDictionary`2 filters, ISessionFactoryImplementor factory) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Hql\Ast\ANTLR\ASTQueryTranslatorFactory.cs:line 33
at NHibernate.Hql.Ast.ANTLR.ASTQueryTranslatorFactory.CreateQueryTranslators(String queryIdentifier, IQueryExpression queryExpression, String collectionRole, Boolean shallow, IDictionary`2 filters, ISessionFactoryImplementor factory) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Hql\Ast\ANTLR\ASTQueryTranslatorFactory.cs:line 27
at NHibernate.Engine.Query.HQLExpressionQueryPlan.CreateTranslators(String expressionStr, IQueryExpression queryExpression, String collectionRole, Boolean shallow, IDictionary`2 enabledFilters, ISessionFactoryImplementor factory) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Engine\Query\HQLExpressionQueryPlan.cs:line 34
at NHibernate.Engine.Query.HQLExpressionQueryPlan..ctor(String expressionStr, IQueryExpression queryExpression, String collectionRole, Boolean shallow, IDictionary`2 enabledFilters, ISessionFactoryImplementor factory) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Engine\Query\HQLExpressionQueryPlan.cs:line 23
at NHibernate.Engine.Query.HQLExpressionQueryPlan..ctor(String expressionStr, IQueryExpression queryExpression, Boolean shallow, IDictionary`2 enabledFilters, ISessionFactoryImplementor factory) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Engine\Query\HQLExpressionQueryPlan.cs:line 17
at NHibernate.Engine.Query.QueryPlanCache.GetHQLQueryPlan(IQueryExpression queryExpression, Boolean shallow, IDictionary`2 enabledFilters) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Engine\Query\QueryPlanCache.cs:line 88
at NHibernate.Impl.AbstractSessionImpl.GetHQLQueryPlan(IQueryExpression queryExpression, Boolean shallow) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Impl\AbstractSessionImpl.cs:line 312
at NHibernate.Impl.AbstractSessionImpl.CreateQuery(IQueryExpression queryExpression) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Impl\AbstractSessionImpl.cs:line 268
at NHibernate.Linq.NhQueryProvider.PrepareQuery(Expression expression, IQuery& query, NhLinqExpression& nhQuery) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Linq\NhQueryProvider.cs:line 43
at NHibernate.Linq.NhQueryProvider.Execute(Expression expression) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Linq\NhQueryProvider.cs:line 26
at NHibernate.Linq.NhQueryProvider.Execute[TResult](Expression expression) in d:\CSharp\NH\NH\nhibernate\src\NHibernate\Linq\NhQueryProvider.cs:line 103
at Remotion.Data.Linq.QueryableBase`1.GetEnumerator() in :line 0
at System.Collections.Generic.List`1..ctor(IEnumerable`1 collection)
at System.Linq.Enumerable.ToList[TSource](IEnumerable`1 source)
at Xmedia.IS24.Test.Persistence.NHDataContextTests.<TakeSkip>b__b(IDataContext dataContext) in C:\SourceGear\ImmoScout24_Main\Webs\IS24Backend\Xmedia.IS24.Test\Persistence\NHDataContextTests.cs:line 134
--------------------------------------

Might be related to

Environment

None

Activity

Show:

Alex Zaytsev 
September 8, 2014 at 11:31 AM

Close issues resolved in 3.3.3

Oskar Berggren 
November 18, 2012 at 7:51 PM

Tests backported to 3.3.x in ebf8ceaa373fff7268bd8510a02d20e1ba67494f. The actual fix was backported under NH-3320.

Alex Zaytsev 
May 21, 2012 at 6:34 PM

Merged to master eb2d2e372af3b884d1ae4127176da33785033ce7

Alex Zaytsev 
April 17, 2012 at 3:28 PM

Oskar Berggren 
April 17, 2012 at 2:35 PM

Regarding the posters query with skip/take before where:
Linq2SQL and Linq2EF both creates subqueries (in the from clause) with the limits, then filters the outcome of the subquery. I.e it may generate a complete different result from putting skip/take after the where clause.

Linq2EF has a check and gives an explicit error unless an OrderBy is added before the Skip.

Fixed

Details

Assignee

Reporter

Components

Fix versions

Affects versions

Priority

Who's Looking?

Open Who's Looking?
Created March 21, 2011 at 9:48 AM
Updated September 8, 2014 at 11:31 AM
Resolved May 21, 2012 at 6:34 PM
Who's Looking?