What is the difference between StatelessSession
and Session
in NHibernate?
C# – the difference between StatelessSession and Session in NHibernate
cnhibernatesession
Related Topic
- C# – What’s the main difference between int.Parse() and Convert.ToInt32
- C# – What are the correct version numbers for C#
- C# – the difference between a field and a property
- C# – What’s the difference between the ‘ref’ and ‘out’ keywords
- C# – In C#, what is the difference between public, private, protected, and having no access modifier
- C# – Difference Between Select and SelectMany
- C# – Calculate difference between two dates (number of days)
- C# – a NullReferenceException, and how to fix it
Best Answer
Stateless session is not tracking entities that are retrieved. For example for regular
ISession
following code:will result in update in DB. This tracking consumes memory and makes
ISession
performance to degrade over time since amount of tracked entities is growing.The same code with
IStatelessSession
won't do anything. Stateless sessions are used when you need to load lots of data and perform some batching operations. It can be used to work with large data sets in a more "ado.net" style.