/// <summary> /// Creates a new transaction scope. The scope can be nested inside another scope /// in which case the underlying db transaction is only commited once both the outer /// and inner transaction(s) have been committed. The returned ITransactionScope /// implements IDisposable and should be wrapped in a using statement. /// </summary> /// <returns>ITransactionScope, which is IDisposable and must be disposed.</returns> public ITransactionScope Create() { ITransactionScope scope; if (_primaryTransactionScope == null) { var transaction = _dbContext.Database.BeginTransaction(); _primaryTransactionScope = new TransactionScope(this, transaction); scope = _primaryTransactionScope; } else { scope = new ChildTransactionScope(_primaryTransactionScope); } return(scope); }
/// <summary> /// Creates a new transaction scope. The scope can be nested inside another scope /// in which case the underlying db transaction is only commited once both the outer /// and inner transaction(s) have been committed. The returned ITransactionScope /// implements IDisposable and should be wrapped in a using statement. /// </summary> /// <returns>ITransactionScope, which is IDisposable and must be disposed.</returns> public ITransactionScope Create(DbContext dbContext) { ITransactionScope scope; var primaryScope = _primaryTransactionScopes.GetOrDefault(dbContext); if (primaryScope == null) { primaryScope = CreateScope(dbContext); _primaryTransactionScopes.Add(dbContext, primaryScope); scope = primaryScope; } else { scope = new ChildTransactionScope(primaryScope); } return(scope); }