简体   繁体   English

NHibernate缓存不适用于匿名类型

[英]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[]'. System.InvalidCastException:无法将类型为“ Baz”的对象转换为类型为“ 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? 有人知道这是NHibernate的限制还是我做错了什么?

LinqToNHibernate is not a full implementation for querying data. LinqToNHibernate不是用于查询数据的完整实现。

Use CriteriaQuery (about 95% coverage off all that is possible to query), or HQL (100% coverage). 使用CriteriaQuery(覆盖所有可能查询的区域约95%)或HQL(覆盖100%)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM