/// <summary> /// Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources. /// </summary> public virtual async ValueTask DisposeAsync() { if (!_disposed) { InterceptionResult?interceptionResult = null; try { _reader.Close(); // can throw interceptionResult = _logger?.DataReaderDisposing( _connection, _command, _reader, _commandId, _reader.RecordsAffected, _readCount, _startTime, _stopwatch.Elapsed); // can throw } finally { _disposed = true; if (interceptionResult == null) { await _reader.DisposeAsyncIfAvailable(); _command.Parameters.Clear(); await _command.DisposeAsyncIfAvailable(); await _connection.CloseAsync(); } } } }
public override InterceptionResult?TransactionRollingBack( DbTransaction transaction, TransactionEventData eventData, InterceptionResult?result) { base.TransactionRollingBack(transaction, eventData, result); return(new InterceptionResult()); }
public override async Task <InterceptionResult?> TransactionRollingBackAsync( DbTransaction transaction, TransactionEventData eventData, InterceptionResult?result, CancellationToken cancellationToken = default) { await base.TransactionRollingBackAsync(transaction, eventData, result, cancellationToken); return(new InterceptionResult()); }
public virtual Task <InterceptionResult?> ConnectionClosingAsync( DbConnection connection, ConnectionEventData eventData, InterceptionResult?result) { Assert.True(eventData.IsAsync); AsyncCalled = true; AssertClosing(eventData); return(Task.FromResult(result)); }
public virtual InterceptionResult?ConnectionClosing( DbConnection connection, ConnectionEventData eventData, InterceptionResult?result) { Assert.False(eventData.IsAsync); SyncCalled = true; AssertClosing(eventData); return(result); }
public InterceptionResult?ConnectionClosing( DbConnection connection, ConnectionEventData eventData, InterceptionResult?result) { for (var i = 0; i < _interceptors.Length; i++) { result = _interceptors[i].ConnectionClosing(connection, eventData, result); } return(result); }
public async Task <InterceptionResult?> ConnectionClosingAsync( DbConnection connection, ConnectionEventData eventData, InterceptionResult?result) { for (var i = 0; i < _interceptors.Length; i++) { result = await _interceptors[i].ConnectionClosingAsync(connection, eventData, result); } return(result); }
public InterceptionResult?DataReaderDisposing( DbCommand command, DataReaderDisposingEventData eventData, InterceptionResult?result) { for (var i = 0; i < _interceptors.Length; i++) { result = _interceptors[i].DataReaderDisposing(command, eventData, result); } return(result); }
public InterceptionResult?TransactionRollingBack( DbTransaction transaction, TransactionEventData eventData, InterceptionResult?result) { for (var i = 0; i < _interceptors.Length; i++) { result = _interceptors[i].TransactionRollingBack(transaction, eventData, result); } return(result); }
public virtual Task <InterceptionResult?> ConnectionOpeningAsync( DbConnection connection, ConnectionEventData eventData, InterceptionResult?result, CancellationToken cancellationToken = default) { Assert.True(eventData.IsAsync); AsyncCalled = true; AssertOpening(eventData); return(Task.FromResult(result)); }
public async Task <InterceptionResult?> ConnectionOpeningAsync( DbConnection connection, ConnectionEventData eventData, InterceptionResult?result, CancellationToken cancellationToken = default) { for (var i = 0; i < _interceptors.Length; i++) { result = await _interceptors[i].ConnectionOpeningAsync(connection, eventData, result, cancellationToken); } return(result); }
public async Task <InterceptionResult?> TransactionRollingBackAsync( DbTransaction transaction, TransactionEventData eventData, InterceptionResult?result, CancellationToken cancellationToken = default) { for (var i = 0; i < _interceptors.Length; i++) { result = await _interceptors[i].TransactionRollingBackAsync(transaction, eventData, result, cancellationToken); } return(result); }
public override InterceptionResult?ConnectionOpening( DbConnection connection, ConnectionEventData eventData, InterceptionResult?result) { base.ConnectionOpening(connection, eventData, result); if (result == null) { connection.Open(); } return(new InterceptionResult()); }
public override async Task <InterceptionResult?> ConnectionOpeningAsync( DbConnection connection, ConnectionEventData eventData, InterceptionResult?result, CancellationToken cancellationToken = default) { await base.ConnectionOpeningAsync(connection, eventData, result, cancellationToken); if (result == null) { await connection.OpenAsync(cancellationToken); } return(new InterceptionResult()); }
/// <summary> /// Called just before EF intends to call <see cref="DbConnection.OpenAsync()" />. /// </summary> /// <param name="connection"> The connection. </param> /// <param name="eventData"> Contextual information about the connection. </param> /// <param name="result"> /// The current result, or null if no result yet exists. /// This value will be non-null if some previous interceptor suppressed execution by returning a result from /// its implementation of this method. /// This value is typically used as the return value for the implementation of this method. /// </param> /// <param name="cancellationToken"> The cancellation token. </param> /// <returns> /// If the <see cref="Task" /> result is null, then EF will open the connection as normal. /// If the <see cref="Task" /> result is non-null value, then connection opening is suppressed. /// A normal implementation of this method for any interceptor that is not attempting to change the result /// is to return the <paramref name="result" /> value passed in, often using <see cref="Task.FromResult{TResult}" /> /// </returns> public virtual Task <InterceptionResult?> ConnectionOpeningAsync( DbConnection connection, ConnectionEventData eventData, InterceptionResult?result, CancellationToken cancellationToken = default) => Task.FromResult(result);
/// <summary> /// Called just before EF intends to call <see cref="DbConnection.Open()" />. /// </summary> /// <param name="connection"> The connection. </param> /// <param name="eventData"> Contextual information about the connection. </param> /// <param name="result"> /// The current result, or null if no result yet exists. /// This value will be non-null if some previous interceptor suppressed execution by returning a result from /// its implementation of this method. /// This value is typically used as the return value for the implementation of this method. /// </param> /// <returns> /// If null, then EF will open the connection as normal. /// If non-null, then connection opening is suppressed. /// A normal implementation of this method for any interceptor that is not attempting to change the result /// is to return the <paramref name="result" /> value passed in. /// </returns> public virtual InterceptionResult?ConnectionOpening( DbConnection connection, ConnectionEventData eventData, InterceptionResult?result) => result;
/// <summary> /// Called just before EF intends to call <see cref="DbConnection.CloseAsync()" /> in an async context. /// </summary> /// <param name="connection"> The connection. </param> /// <param name="eventData"> Contextual information about the connection. </param> /// <param name="result"> /// The current result, or null if no result yet exists. /// This value will be non-null if some previous interceptor suppressed execution by returning a result from /// its implementation of this method. /// This value is typically used as the return value for the implementation of this method. /// </param> /// <returns> /// If the <see cref="Task" /> result is null, then EF will close the connection as normal. /// If the <see cref="Task" /> result is non-null value, then connection closing is suppressed. /// A normal implementation of this method for any interceptor that is not attempting to change the result /// is to return the <paramref name="result" /> value passed in, often using <see cref="Task.FromResult{TResult}" /> /// </returns> public virtual Task <InterceptionResult?> ConnectionClosingAsync( DbConnection connection, ConnectionEventData eventData, InterceptionResult?result) => Task.FromResult(result);
/// <summary> /// Called just before EF intends to call <see cref="DbTransaction.Rollback" />. /// </summary> /// <param name="transaction"> The transaction. </param> /// <param name="eventData"> Contextual information about connection and transaction. </param> /// <param name="result"> /// The current result, or null if no result yet exists. /// This value will be non-null if some previous interceptor suppressed rolling back by returning a result from /// its implementation of this method. /// This value is typically used as the return value for the implementation of this method. /// </param> /// <returns> /// If null, then EF will roll back the transaction as normal. /// If non-null, then rolling back the transaction is suppressed. /// A normal implementation of this method for any interceptor that is not attempting to change the result /// is to return the <paramref name="result" /> value passed in. /// </returns> public virtual InterceptionResult?TransactionRollingBack( DbTransaction transaction, TransactionEventData eventData, InterceptionResult?result) => result;
/// <summary> /// Called just before EF intends to call <see cref="DbTransaction.Rollback" />. /// </summary> /// <param name="transaction"> The transaction. </param> /// <param name="eventData"> Contextual information about connection and transaction. </param> /// <param name="result"> /// The current result, or null if no result yet exists. /// This value will be non-null if some previous interceptor suppressed rolling back returning a result from /// its implementation of this method. /// This value is typically used as the return value for the implementation of this method. /// </param> /// <param name="cancellationToken"> The cancellation token. </param> /// <returns> /// If the <see cref="Task" /> result is null, then EF will roll back the transaction as normal. /// If the <see cref="Task" /> result is non-null value, rolling back the transaction is suppressed. /// A normal implementation of this method for any interceptor that is not attempting to change the result /// is to return the <paramref name="result" /> value passed in, often using <see cref="Task.FromResult{TResult}" /> /// </returns> public virtual Task <InterceptionResult?> TransactionRollingBackAsync( DbTransaction transaction, TransactionEventData eventData, InterceptionResult?result, CancellationToken cancellationToken = default) => Task.FromResult(result);
/// <summary> /// Called when execution of a <see cref="DbDataReader"/> is about to be disposed. />. /// </summary> /// <param name="command"> The command. </param> /// <param name="eventData"> Contextual information about the command and reader. </param> /// <param name="result"> /// The current result, or null if no result yet exists. /// This value will be non-null if some previous interceptor suppressed execution by returning a result from /// its implementation of this method. /// This value is typically used as the return value for the implementation of this method. /// </param> /// <returns> /// If null, then EF will dispose the reader as normal. /// If non-null, then disposing the reader is suppressed. /// A normal implementation of this method for any interceptor that is not attempting to change the result /// is to return the <paramref name="result" /> value passed in. /// </returns> public virtual InterceptionResult?DataReaderDisposing( DbCommand command, DataReaderDisposingEventData eventData, InterceptionResult?result) => result;
/// <summary> /// Called just before EF intends to call <see cref="DbTransaction.Commit" />. /// </summary> /// <param name="transaction"> The transaction. </param> /// <param name="eventData"> Contextual information about connection and transaction. </param> /// <param name="result"> /// The current result, or null if no result yet exists. /// This value will be non-null if some previous interceptor suppressed committing by returning a result from /// its implementation of this method. /// This value is typically used as the return value for the implementation of this method. /// </param> /// <returns> /// If null, then EF will committing the transaction as normal. /// If non-null, then committing the transaction is suppressed. /// A normal implementation of this method for any interceptor that is not attempting to change the result /// is to return the <paramref name="result" /> value passed in. /// </returns> public virtual InterceptionResult?TransactionCommitting( DbTransaction transaction, TransactionEventData eventData, InterceptionResult?result) => result;