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 thatFindAll()
can not benefit is that it internally usesICriteria
andICriteria
itself can not use first level cache. First level cache is available just forLoad
andGet
.More info available here.