/// <summary> /// Executes the specified operation in a transaction and returns the result. Allows to check whether /// the transaction has been rolled back if an error occurs during commit. /// </summary> /// <param name="strategy"> The strategy that will be used for the execution. </param> /// <param name="operation"> /// A delegate representing an executable operation that returns the result of type <typeparamref name="TResult" />. /// </param> /// <param name="verifySucceeded"> /// A delegate that tests whether the operation succeeded even though an exception was thrown when the /// transaction was being committed. /// </param> /// <typeparam name="TResult"> The return type of <paramref name="operation" />. </typeparam> /// <returns> The result from the operation. </returns> /// <exception cref="RetryLimitExceededException"> /// The operation has not succeeded after the configured number of retries. /// </exception> public static TResult ExecuteInTransaction <TResult>( [NotNull] this IExecutionStrategy strategy, [NotNull] Func <TResult> operation, [NotNull] Func <bool> verifySucceeded) => strategy.ExecuteInTransaction <object, TResult>(null, s => operation(), s => verifySucceeded());
/// <summary> /// Executes the specified operation in a transaction and returns the result. Allows to check whether /// the transaction has been rolled back if an error occurs during commit. /// </summary> /// <remarks> /// See <see href="https://aka.ms/efcore-docs-connection-resiliency">Connection resiliency and database retries</see> /// for more information and examples. /// </remarks> /// <param name="strategy">The strategy that will be used for the execution.</param> /// <param name="operation"> /// A delegate representing an executable operation that returns the result of type <typeparamref name="TResult" />. /// </param> /// <param name="verifySucceeded"> /// A delegate that tests whether the operation succeeded even though an exception was thrown when the /// transaction was being committed. /// </param> /// <typeparam name="TResult">The return type of <paramref name="operation" />.</typeparam> /// <returns>The result from the operation.</returns> /// <exception cref="RetryLimitExceededException"> /// The operation has not succeeded after the configured number of retries. /// </exception> public static TResult ExecuteInTransaction <TResult>( this IExecutionStrategy strategy, Func <TResult> operation, Func <bool> verifySucceeded) => strategy.ExecuteInTransaction <object?, TResult>(null, _ => operation(), _ => verifySucceeded());
/// <summary> /// Executes the specified operation in a transaction. Allows to check whether /// the transaction has been rolled back if an error occurs during commit. /// </summary> /// <param name="strategy"> The strategy that will be used for the execution. </param> /// <param name="operation"> /// A delegate representing an executable operation. /// </param> /// <param name="verifySucceeded"> /// A delegate that tests whether the operation succeeded even though an exception was thrown when the /// transaction was being committed. /// </param> /// <exception cref="RetryLimitExceededException"> /// The operation has not succeeded after the configured number of retries. /// </exception> public static void ExecuteInTransaction( [NotNull] this IExecutionStrategy strategy, [NotNull] Action operation, [NotNull] Func <bool> verifySucceeded) => strategy.ExecuteInTransaction <object>(null, s => operation(), s => verifySucceeded());
/// <summary> /// Executes the specified operation in a transaction. Allows to check whether /// the transaction has been rolled back if an error occurs during commit. /// </summary> /// <remarks> /// See <see href="https://aka.ms/efcore-docs-connection-resiliency">Connection resiliency and database retries</see> /// for more information and examples. /// </remarks> /// <param name="strategy">The strategy that will be used for the execution.</param> /// <param name="operation"> /// A delegate representing an executable operation. /// </param> /// <param name="verifySucceeded"> /// A delegate that tests whether the operation succeeded even though an exception was thrown when the /// transaction was being committed. /// </param> /// <exception cref="RetryLimitExceededException"> /// The operation has not succeeded after the configured number of retries. /// </exception> public static void ExecuteInTransaction( this IExecutionStrategy strategy, Action operation, Func <bool> verifySucceeded) => strategy.ExecuteInTransaction <object?>(null, _ => operation(), _ => verifySucceeded());