开发者

NHibernate caching not working for anonymous type

I am trying to get the following query to work:

Session.Linq<FooBar>()
    .SetCachable(true)
    .SetCacheRegion("foobar开发者_C百科")
    .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).

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜