views:

14

answers:

1

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>();
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?

A: 

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.

http://stackoverflow.com/questions/2350683/nhibernate-cache-problem-with-linq-queries/3931948

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.

Hainesy