为Linq查询提供流畅的NHibernate缓存

时间:2010-10-11 11:55:39

标签: caching fluent-nhibernate linq-to-nhibernate

我刚刚发现我认为我的nhibernate设置似乎没有正确缓存。我正在运行一个SQL服务器探查器,第一级或第二级缓存似乎都没有工作。

我正在使用的查询:

var queryable = NHibernateSession.CurrentFor(NHibernateSession.DefaultFactoryKey).Linq<Accommodation>();
queryable.QueryOptions.SetCachable(true);

我也试过在其中一个实体映射中设置它:

Cache.Is(c => c.ReadOnly());

我还应该做些什么吗?

1 个答案:

答案 0 :(得分:1)

如果涉及select语句,则有人建议二级缓存不能运行linq查询。我不知道这是不是一个错误。

nhibernate cache problem with linq queries

值得检查的另一件事是使用显式交易:

http://www.markhneedham.com/blog/2010/06/16/fluent-nhibernate-and-the-2nd-level-cache/

等待NH 3.0以及更新,更好的linq集成可能更为明智。