There is a session.Lock(object)
method.
When you call session.Save(object)
, NHibernate isn't doing anything in the database until it gets flushed.
Flushing is done (depending on the flush mode, which is usually AutoFlush)
- before queries (except Get and Load)
- when calling flush explicitly
- when committing the transaction (if the connection is created by NH I think)
When the session is flushed, the actual update, insert and delete operations are done on the database and locks are set.
In SQL Server, when the lock is set, the reading transaction is waiting until commit of the updating transaction. When it commits, it reads the committed values (when you are in "Read Committed" isolation).
Stefan Steinegger
2010-08-20 10:16:48