NHibernate caching not working for anonymous type

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?


LinqToNHibernate is not a full implementation for querying data.

Use CriteriaQuery (about 95% coverage off all that is possible to query), or HQL (100% coverage).

链接地址: http://www.djcxy.com/p/71052.html

上一篇: NHibernate会保存,但不会加载实体

下一篇: NHibernate缓存不适用于匿名类型