The contents of this section
Transactions Overview
1. New Object
"Test submitted successfully"
"Test Failure rollback"
2. Delete objects
3. Update objects
4. Save updated objects
Conclusion
In the previous article we introduced the INSERT, Update, delete operation in NHibernate, this article we look at the transaction in NHibernate. You can submit or rollback your operation through it.
Transaction Overview 1. Transactions in NHibernate (transactions)
Simple description: Require ISession to use transactions; do something; commit or roll back a transaction.
Write code like this:
ITransaction tx = _session.BeginTransaction();
//一些保存、更新、删除等操作
tx.Commit();
In fact, using a transaction in NHibernate is used to force resource cleanup and exception mechanisms, generally like this:
using (ITransaction tx = _session.BeginTransaction())
{
try
{
//一些保存、更新、删除等操作
tx.Commit();
}
catch (HibernateException)
{
tx.Rollback();
throw;
}
}