When using NHibernate and the unit of work for a query, in what scenarios would it be beneficial to use multiple transactions for each query?

In my web application, the session is created in the BeginRequest handler. All database operations are performed on this session. In the EndRequest handler, a session is used to create a transaction, which is then executed. After that, the session is deleted. This completes all database operations performed against the session in a single transaction.

When is it useful to create a transaction that will be committed as part of a request transaction? How it's done?

In other words, for what reason can I create a transaction for any purpose other than to perform all database operations performed in the current request?

+3
source share
2 answers

When a user visits a page, you want to register various things in the database - Page Hit, etc. This may succeed in the same session, but you want page tracking to be reset to the database, even if an error subsequently occurs.

For better performance, you will also want your transactions to open as short as possible. During your request, you can perform many non-database operations, for which there is no reason to open a transaction.

Many other examples ...

+1
source

. .Commit // , , . - - . , -, , - .

, - , BeingRequest EndRequest .

, EndRequest, - , , , /.

0

Source: https://habr.com/ru/post/1760413/


All Articles