O'Reilly logo

NHibernate 3 Beginner's Guide by Gabriel N. Schenker

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

No database operation without a transaction

Whenever we execute operations that manipulate data in a database, we should wrap these operations inside a transaction:

using( var session = sessionFactory.OpenSession())
{
  using (var transaction = session.BeginTransaction())
  {
    // code that manipulates data…
  }
}

Each relational database product automatically generates an implicit transaction for us if we do not use our own explicit transaction. This has several drawbacks, one of them being that each single task is a transaction. Multiple tasks cannot be handled as a single unit of work. Additionally, there is also a slight performance penalty to be expected if not using explicit transactions wrapping multiple tasks.

Should I use transactions when querying ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required