I have a function which gets called many times in one session. To my understanding with NHibernate first level cache, exact query in the same session will execute only once irrespective of the number of calls.
Such is not the case though. Below is the snippet and I can see the query being executed in NHProfiler as many times the function is called.
public List<CustomerType> GetAllActiveCustomerTypes()
{
return _unitOfWork.CurrentSession.QueryOver<CustomerType>().Where(x => x.Active).List();
}
Am I missing something in understanding NHibernate here?
Thanks
Your experience is correct. Queries are not cached by a sessions first-level cache. To extend the understanding read this:First and Second Level caching in NHibernate
The extract of the first-level cache:
and
As said, it serves for
entity
caching purposes.The Second level cache extract: