开发者

NHibernate 3 - TransactionScope vs. NHibernate transactions

I ne开发者_如何学运维ed to choose between TransactionScope or NHibernate transactions for my new project. What is better? When should use TransactionScope? NHibernate transactions?


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜