I am trying to get the following query to work:
Session.Linq<FooBar>()
.SetCachable(true)
.SetCacheRegion("foobar")
.Select(x => new Baz(x.Foo, x.Bar))
.ToList();
This works when caching is turned off, but with caching enabled I receive the following exception:
System.InvalidCastException: Unable to cast object of type 'Baz' to type 'System.Object[]'.
The rest of the stack trace is:
at NHibernate.Cache.StandardQueryCache.Put(QueryKey key, ICacheAssembler[] returnTypes, IList result, Boolean isNaturalKeyLookup, ISessionImplementor session)
at NHibernate.Loader.Loader.PutResultInQueryCache(ISessionImplementor session, QueryParameters queryParameters, IType[] resultTypes, IQueryCache queryCache, QueryKey key, IList result)
at NHibernate.Loader.Loader.ListUsingQueryCache(ISessionImplementor session, QueryParameters queryParameters, ISet`1 querySpaces, IType[] resultTypes)
at NHibernate.Loader.Loader.List(ISessionImplementor session, QueryParameters queryParameters, ISet`1 querySpaces, IType[] resultTypes)
at NHibernate.Impl.SessionImpl.List(CriteriaImpl criteria, IList results)
Anyone know if this is an NHibernate limitation or am I doing something wrong?