NHibernate 缓存不适用于匿名类型
我试图让以下查询工作:
Session.Linq<FooBar>()
.SetCachable(true)
.SetCacheRegion("foobar")
.Select(x => new Baz(x.Foo, x.Bar))
.ToList();
这在缓存关闭时有效,但在启用缓存的情况下我 收到以下异常:
System.InvalidCastException:无法将类型为“Baz”的对象转换为 输入“System.Object[]”。
堆栈跟踪的其余部分是:
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)
有人知道这是 NHibernate 的限制还是我做错了什么?
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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
LinqToNHibernate 不是查询数据的完整实现。
使用 CriteriaQuery(所有可能查询的覆盖率约为 95%)或 HQL(100% 覆盖率)。
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).