nhibernatecachingisession

How to get NHibernate ISession to cache entity not retrieved by primary key


My 'user' entity is almost always retrieved by username, rather than by its integer surrogate key. Because the username is not the primary key, this means that the ISession won't cache it and repeatedly hits the database to get the same data.

Is there any way at all I can configure NHibernate to get the ISession to cache users retrieved by username?


Solution

  • It seems the answer is in fact no. Yes, if you're using the second level cache, no if you are using the Session cache.