NHibernate Tour (6): Exploring the affairs in NHibernate

Source: Internet
Author: User
Tags commit rollback

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;
  }
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.