protected override void OnDisposing(bool disposing) { if (!disposing) { return; } var dbContext = RetrieveValidContext(); DbContextTransaction transaction = null; if (_transaction.IsNotNull()) { _transaction.TryGetTarget(out transaction); } if (transaction.IsNull()) { if (_disposeDbContext) { dbContext.Dispose(); } return; } try { transaction.Commit(); } catch { transaction.Rollback(); throw; } finally { transaction.Dispose(); if (_disposeDbContext) { dbContext.Dispose(); } } }