Andy
Andy

Reputation: 764

NHibernate 3 - TransactionScope vs. NHibernate transactions

I need to choose between TransactionScope or NHibernate transactions for my new project. What is better? When should use TransactionScope? NHibernate transactions?

Upvotes: 2

Views: 1598

Answers (2)

mostafa63
mostafa63

Reputation: 5

Transaction management is exposed to the application developer via the NHibernate ITransaction interface. You aren’t forced to use this API—NHibernate lets you control ADO.NET transactions directly.

Upvotes: 0

Diego Mijelshon
Diego Mijelshon

Reputation: 52745

They are different things.

You should always do your work inside a NHibernate transaction.

You can use TransactionScope as needed, for example. to use distributed transactions when there's more than one session involved.

NHibernate transactions will automatically enlist in distributed transactions, but they won't be created automatically, so the recommended pattern is: if you have a TransactionScope, open the NH transaction inside it.

Upvotes: 6

Related Questions