Fluent NHibernate Cacheing for Linq queries
I have just discovered that I don't think my nhibernate setup seems to be cacheing properly. I'm running a SQL server profiler and neither the 1st or 2nd level cache appear to be working.
For my queries I'm using:
var queryable = NHibernateSession.CurrentFor(NHibernateSession.DefaultFactoryKey).Linq<Accommodation>开发者_Python百科();
queryable.QueryOptions.SetCachable(true);
I've also tried setting this in one of the entity mappings:
Cache.Is(c => c.ReadOnly());
Is there something else I ought to be doing?
One person suggests that the 2nd-level cache does not work linq queries if there's a select statement involved. I don't know whether this is a bug or not.
nhibernate cache problem with linq queries
Another thing worth checking is using explicit transactions:
http://www.markhneedham.com/blog/2010/06/16/fluent-nhibernate-and-the-2nd-level-cache/
It's probably more sensible to wait for NH 3.0 and the newer, better linq integration.
精彩评论