/// <summary> /// Called just before EF intends to call <see cref="DbConnection.BeginTransaction(IsolationLevel)" />. /// </summary> /// <param name="connection"> The connection. </param> /// <param name="eventData"> Contextual information about connection and transaction. </param> /// <param name="result"> /// Represents the current result if one exists. /// This value will have <see cref="InterceptionResult{DbTransaction}.HasResult" /> set to <see langword="true" /> if some previous /// interceptor suppressed execution by calling <see cref="InterceptionResult{DbTransaction}.SuppressWithResult" />. /// This value is typically used as the return value for the implementation of this method. /// </param> /// <returns> /// If <see cref="InterceptionResult{DbTransaction}.HasResult" /> is false, the EF will continue as normal. /// If <see cref="InterceptionResult{DbTransaction}.HasResult" /> is true, then EF will suppress the operation it /// was about to perform and use <see cref="InterceptionResult{DbTransaction}.Result" /> instead. /// 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 InterceptionResult <DbTransaction> TransactionStarting( DbConnection connection, TransactionStartingEventData eventData, InterceptionResult <DbTransaction> result) => result;
/// <summary> /// Called just before EF intends to call /// <see cref="M:System.Data.Common.DbConnection.BeginTransactionAsync(System.Data.IsolationLevel,System.Threading.CancellationToken)" />. /// </summary> /// <param name="connection"> The connection. </param> /// <param name="eventData"> Contextual information about connection and transaction. </param> /// <param name="result"> /// Represents the current result if one exists. /// This value will have <see cref="InterceptionResult{DbTransaction}.HasResult" /> set to <see langword="true" /> if some previous /// interceptor suppressed execution by calling <see cref="InterceptionResult{DbTransaction}.SuppressWithResult" />. /// 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 <see cref="InterceptionResult{DbTransaction}.HasResult" /> is false, the EF will continue as normal. /// If <see cref="InterceptionResult{DbTransaction}.HasResult" /> is true, then EF will suppress the operation it /// was about to perform and use <see cref="InterceptionResult{DbTransaction}.Result" /> instead. /// 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 ValueTask <InterceptionResult <DbTransaction> > TransactionStartingAsync( DbConnection connection, TransactionStartingEventData eventData, InterceptionResult <DbTransaction> result, CancellationToken cancellationToken = default) => new ValueTask <InterceptionResult <DbTransaction> >(result);
/// <summary> /// Called just before EF intends to call <see cref="DbConnection.BeginTransaction(IsolationLevel)" />. /// </summary> /// <param name="connection"> The connection. </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 creation 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 start the transaction as normal. /// If the <see cref="Task" /> result is non-null value, then transaction creation is suppressed and the value contained in /// the <see cref="InterceptionResult{TResult}" /> we be used by EF instead. /// 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 <DbTransaction>?> TransactionStartingAsync( DbConnection connection, TransactionStartingEventData eventData, InterceptionResult <DbTransaction>?result, CancellationToken cancellationToken = default) => Task.FromResult(result);