public static bool TryBeginTransaction(this WrappedConnection wrappedConnection) { if (wrappedConnection.CurrentTx is null && Transaction.Current is null) { // No current tx, no ambient tx wrappedConnection.BeginTransaction(); return(true); } return(false); }
public static bool TryBeginTransaction(this WrappedConnection wrappedConnection) { if (wrappedConnection.CurrentTx == null) { wrappedConnection.BeginTransaction(); return(true); } return(false); }
public void When_commit_transaction_is_cleared() { using (var wrappedConnection = new WrappedConnection(new SqliteConnection("Data Source=:memory:"))) { var tx = wrappedConnection.BeginTransaction(); wrappedConnection.Commit(); Assert.Null(wrappedConnection.CurrentTx); } }
public void BeginTransaction_opens_a_connection_and_returns_a_transaction() { var cnn = new SqliteConnection("Data Source=:memory:"); using (var wrappedConnection = new WrappedConnection(cnn)) { var tx = wrappedConnection.BeginTransaction(); Assert.NotNull(wrappedConnection.CurrentTx); Assert.True(wrappedConnection.DbConnection.State == ConnectionState.Open); } Assert.True(cnn.State == ConnectionState.Closed); }
public void BeginTransaction_opens_a_connection_and_returns_a_transaction() { var cnn = _pgContainer.CreateDbConnection(); using (var wrappedConnection = new WrappedConnection(cnn)) { var tx = wrappedConnection.BeginTransaction(); Assert.NotNull(wrappedConnection.CurrentTx); Assert.True(wrappedConnection.DbConnection.State == ConnectionState.Open); } Assert.True(cnn.State == ConnectionState.Closed); }
/// <inheritdoc cref="DbConnection.BeginDbTransaction(IsolationLevel)" /> protected override DbTransaction BeginDbTransaction(IsolationLevel isolationLevel) { if (Profiler == null || !Profiler.IsEnabled) { return(WrappedConnection.BeginTransaction(isolationLevel)); } Profiler.OnStartingTransaction(this); var transaction = WrappedConnection.BeginTransaction(isolationLevel); Profiler.OnStartedTransaction(transaction); return(new AdoNetProfilerDbTransaction(transaction, WrappedConnection, Profiler)); }
/// <summary> /// Starts a database transaction. /// </summary> /// <param name="isolationLevel">Specifies the isolation level for the transaction.</param> /// <returns> /// An object representing the new transaction. /// </returns> protected override DbTransaction BeginDbTransaction(IsolationLevel isolationLevel) { switch (isolationLevel) { case IsolationLevel.Serializable: return(new JetTransaction(WrappedConnection.BeginTransaction(IsolationLevel.ReadCommitted), this)); case IsolationLevel.Chaos: case IsolationLevel.ReadCommitted: case IsolationLevel.ReadUncommitted: case IsolationLevel.RepeatableRead: case IsolationLevel.Snapshot: case IsolationLevel.Unspecified: default: return(new JetTransaction(WrappedConnection.BeginTransaction(isolationLevel), this)); } }
///// <summary> ///// Gets the <see cref="T:System.Data.Common.DbProviderFactory"/> for this <see cref="T:System.Data.Common.DbConnection"/>. ///// </summary> ///// <value></value> ///// <returns> ///// A <see cref="T:System.Data.Common.DbProviderFactory"/>. ///// </returns> //protected override DbProviderFactory DbProviderFactory //{ // get { return EFCachingProviderFactory.Instance; } //} /// <summary> /// Starts a database transaction. /// </summary> /// <param name="isolationLevel">Specifies the isolation level for the transaction.</param> /// <returns> /// An object representing the new transaction. /// </returns> protected override DbTransaction BeginDbTransaction(IsolationLevel isolationLevel) { return(new EFCachingTransaction(WrappedConnection.BeginTransaction(isolationLevel), this)); }
protected override DbTransaction BeginDbTransaction(IsolationLevel isolationLevel) { return(WrappedConnection.BeginTransaction(isolationLevel)); }