【发布时间】:2015-02-15 21:47:54
【问题描述】:
我们在我们的 asp.net mvc 4 (.net 4) 应用程序中使用 NHibernate 4。据我所知,NHibernate 4 的行为在二级缓存方面发生了一些变化。
以下行为似乎发生了变化(如果我错了,请纠正我):
- 使用二级缓存时不再需要事务
- 当我执行 (Hibsession.Query().Where(x => x.Name == "x").ToList()) 之类的查询时,它将查询整个实体。在 NHibernate 的早期版本中——如果我没记错的话——只有实体的 id 会被检索到。
在我看来,二级仅适用于以下情况:
using (var hibSession = SessionFactory.OpenSession())
{
// Second level cache working
var entity = hibSession.Get<ChachedEntity>(7); // second level cache working
var parent = entity.ParentElement; // second level cache working because n:1
// Probably working (not tested)
var elements = hibSession.Query<ChachedEntity>().Cacheable().Take(30).ToList(); // guessed behaviour: query-cache selects id's and then then uses second level cache
// second level cache NOT Working
var children = entity.ChildCollectionWithCachableEntities; // second level cache NOT working because 1:n (!!)
}
我现在的问题是:
- 在哪里描述了 NHibernate 4 二级缓存的行为(或至少记录了对版本 3 的更改)
- 是否可以使用二级缓存来延迟加载子元素? (或者至少确保只加载 id,然后让二级缓存实现实体)
提前致谢
【问题讨论】:
标签: nhibernate second-level-cache