0

For example:

User user = GetSession().Query<User>().SingleOrDefault(u => u.Login == login);

That query could evaluated twice in my code from different methods (check if user exist and save some data to cookies). Profiler shows that nhibernate accessed database twice for that query inside one session. Is it possible to configure nhiberate/mappings do not execute the same queries inside same session?

Thanks in advance

Ievgen Martynov
  • 7,870
  • 8
  • 36
  • 52

1 Answers1

1

Sounds like you want second-level caching and the query cache.

From the NHibernate reference, section 19.4 The Query Cache:

Query result sets may also be cached. This is only useful for queries that are run frequently with the same parameters.

Oskar Berggren
  • 5,583
  • 1
  • 19
  • 36