We're updating the issue view to help you get more done. 

using Skip(aNumber).Count() where aNumber is greater than total count of records results in ArgumentOutOfRangeException

Description

Happens with any mapped entity, where aNumber is greater than the number of results:

Session.Query<Entity>().Skip(aNumber).Count()

Or an example case for us in pagination:

var recordsOnThisPage = Session.Query<Entity>().Skip((pageNumber - 1) * recordsPerPage).Take(recordsPerPage).Count()

Will result in:

System.ArgumentOutOfRangeException : Index was out of range. Must be non-negative and less than the size of the collection.
Parameter name: index

at System.ThrowHelper.ThrowArgumentOutOfRangeException(ExceptionArgument argument, ExceptionResource resource)
at System.Collections.Generic.List`1.System.Collections.IList.get_Item(Int32 index)
at NHibernate.Linq.DefaultQueryProvider.ExecuteQuery(NhLinqExpression nhLinqExpression, IQuery query, NhLinqExpression nhQuery)
at NHibernate.Linq.DefaultQueryProvider.Execute(Expression expression)
at NHibernate.Linq.DefaultQueryProvider.Execute[TResult](Expression expression)
at System.Linq.Queryable.Count[TSource](IQueryable`1 source)

Environment

SQL Server 2008 and SQLite.

Status

Assignee

Unassigned

Reporter

John Thornborrow

Labels

Components

Affects versions

4.0.4

Priority

Major