private IDbConnection GetConnection() { IDbConnection connection; if (ScopeIsActive) { var transaction = ThreadStorage.GetData <IDbTransaction>(TransactionScope.ScopeTransactionKey); if (transaction != null) { connection = transaction.Connection; } else { connection = this.GetDbConnection(); connection.Open(); transaction = connection.BeginTransaction(); ThreadStorage.SetData(TransactionScope.ScopeTransactionKey, transaction); } } else { connection = this.GetDbConnection(); connection.Open(); } return(connection); }
public TransactionScope() { ThreadStorage.SetData(ActiveScopeKey, true); }