NHibernate's first level cache is available when one use same session. ActiveRecordBase.FindAll()
each time creates a new ISession
. So such a following can not profit from first level cache:
void test1()
{
Car.FindAll();
Car.FindAll();
Car.FindAll();
}
Is there any solution?
Calling several FindAll()
does not force several different sessions. They all use a same session. The reason that FindAll()
can not benefit is that it internally uses ICriteria
and ICriteria
itself can not use first level cache. First level cache is available just for Load
and Get
.
More info available here.