ArgumentNullException when caching a sqlquery on NHibernate

371 views Asked by At

Environment: NHibernate 4.0.0.4000; NHibernate.Caches.SysCache 4.0.0.4000; Web MVC/API 4.5.1; FluentNHibernate 1.4.0.0; VS2013;

I'm trying to cache a SQL Query on nhibernate (which works perfectly without caching) as you can see:

        return Session.CreateSQLQuery(sql)
            .AddScalar("Id", NHibernateUtil.Int32)
            .AddScalar("Summary", NHibernateUtil.String)
            .SetResultTransformer(Transformers.AliasToBean<ProductDto>())
            .SetCacheable(true)
            //.SetCacheRegion("Long") throws same error regardless of this
            .List<ProductDto>()
            ;

but it keeps throwing ArgumentNullException, see the details:

Value cannot be null.
Parameter name: source
  at System.Linq.Enumerable.Count[TSource](IEnumerable`1 source, Func`2 predicate)
   at NHibernate.Util.ArrayHelper.CountTrue(Boolean[] array)
   at NHibernate.Transform.CacheableResultTransformer.Create
   ...

I have tried to use another caching provider, namely NHibernate.Caches.RtMemoryCache, but the error is the same.

Also no nhibernate information is logged after the call, as the error apparently happens at a very early stange on its pipeline.

The cache configuration, using Fluent NHibernate:

 (OracleClientConfiguration.Oracle10.ConnectionString(connStr).AdoNetBatchSize(20000)).Cache(c => c.ProviderClass<SysCacheProvider>().UseSecondLevelCache().UseQueryCache())

Log information on cache setup (changes if I use region, naturally):

INFO  2014-11-03 08:51:33,474 [1    ] NHibernate.Cache.StandardQueryCache      - starting query cache at region: NHibernate.Cache.StandardQueryCache

Any ideas? Or maybe the question lacks information?

Thanks!

0

There are 0 answers