Hello,
I am writing custom paging in an ASP.NET application using NHibernate for data access. I am making use of IQuery and Future, FutureValue, SetFirstResult, and SetMaxResult in the paging implementation. I have two queries: one to fetch a page of data which match certain criteria and the other to fetch the count of all data with that criteria. I have verified using the SQL Server Profiler that the SQL is executed successfully, however, I get the following exception:
Code:
[ArgumentException: The value "28" is not of type "System.Int32" and cannot be used in this generic collection.
Parameter name: value]
System.ThrowHelper.ThrowWrongValueTypeArgumentException(Object value, Type targetType) +122
System.Collections.Generic.List`1.VerifyValueType(Object value) +2533366
System.Collections.Generic.List`1.System.Collections.IList.Add(Object item) +15
NHibernate.Impl.MultiQueryImpl.DoList() +1505
[HibernateException: Failed to execute multi query: ...
Here is the core piece of code:
Code:
...
IQuery q = Session.CreateQuery(query);
int firstResult = pageIndex * pageSize;
q.SetFirstResult(firstResult);
q.SetMaxResults(pageSize);
IEnumerable<DataSourceBO> retVal = q.Future<DataSourceBO>();
IQuery qCount = Session.CreateQuery(countQuery);
var futureValue = qCount.FutureValue<int>();
totalCount = futureValue.Value;//exception occurs here
return retVal.ToList();
Anyone have an idea what may be causing the exception? Thanks in advance for your help.