【发布时间】:2011-01-05 19:04:40
【问题描述】:
我的 NHibernate 背景是 Entity Framework v4.0。当我将实体加载到 ObjectContext 中时,我希望只要 ObjectContext 存在(“一级缓存”),它们就会被缓存在那里。因此,如果第二次执行相同的查询,则对象已经在 ObjectContext 中,不应再次加载。
看看这个查询:
using (var context = new Model1Container()) {
//load entities from DB
var entities = context.Entity1Set.ToArray();
//entities should now be cached in the context (1st level cache)
//why does this call not use the cached items?
entities = context.Entity1Set.ToArray();
}
在 SQL Server Profiler 中,我可以清楚地看到两个 ToArray() 调用都会触发数据库查询。为什么第二个查询需要数据库往返,而不是 NHibernate 行为?
谢谢!
【问题讨论】:
标签: .net entity-framework