Nhibernate throws a cast error when CreateSQLQuery() is used with SetCacheable() and when trying to return a scalar value. The fix for this problem is to use the AddScalar() method. Thanks to this google group message.
var sql = "Select count(*) as totalCount from myTables";
var count = session.CreateSQLQuery(sql)
.AddScalar("totalCount", NHibernateUtil.Int32) .SetCacheable(true)
.FutureValue<int>();
Just what I needed. So few nHibernate resources out there. Thanks.
ReplyDelete