Does ServiceStack OrmLite support nested transactions? If so, how?

I am looking for a working example of an external method containing a transaction that calls an internal method that also contains a transaction. Typically, these kinds of things are managed using TransactionScope, but this does not seem to work with ServiceStack OrmLite.

To be clear, I am not looking for how to set up a transaction. I'm looking for how to set up nested transactions so that the innermost transactions are included in the most remote transaction using OrmLite.

+4
source share
1 answer

, , , . SqlServer, .

. , InvalidOperationException: SqlConnection does not support parallel transactions.

:

using (var db = dbFactory.Open())
using (var tran = db.OpenTransaction())
{
  // operations on db...
  using (var nestedDb = dbFactory.Open())
  using (var nestedTran = nestedDb.OpenTransaction())
  { // .Rollback/.Commit as required }
}

, nestedTran.Commit() tran.Rollback(), , nestedTran, , .

, TransactionScope, OrmLite.SqlServer.

0

Source: https://habr.com/ru/post/1532097/


All Articles