Beispiel #1
0
        /// <summary>
        /// Deletes an existing data from the database in an asynchronous way.
        /// </summary>
        /// <param name="connection">The connection object to be used.</param>
        /// <param name="request">The actual <see cref="DeleteRequest"/> object.</param>
        /// <param name="param">The mapped object parameters.</param>
        /// <param name="commandTimeout">The command timeout in seconds to be used.</param>
        /// <param name="transaction">The transaction to be used.</param>
        /// <param name="trace">The trace object to be used.</param>
        /// <returns>The number of rows affected by the execution.</returns>
        internal static async Task <int> DeleteAsyncInternalBase(this IDbConnection connection,
                                                                 DeleteRequest request,
                                                                 object param,
                                                                 int?commandTimeout         = null,
                                                                 IDbTransaction transaction = null,
                                                                 ITrace trace = null)
        {
            // Validate
            InvokeValidatorValidateDeleteAsync(connection);

            // Variables
            var commandType = CommandType.Text;
            var commandText = CommandTextCache.GetDeleteText(request);

            // Before Execution
            if (trace != null)
            {
                var cancellableTraceLog = new CancellableTraceLog(commandText, param, null);
                trace.BeforeDelete(cancellableTraceLog);
                if (cancellableTraceLog.IsCancelled)
                {
                    if (cancellableTraceLog.IsThrowException)
                    {
                        throw new CancelledExecutionException(commandText);
                    }
                    return(0);
                }
                commandText = (cancellableTraceLog.Statement ?? commandText);
                param       = (cancellableTraceLog.Parameter ?? param);
            }

            // Before Execution Time
            var beforeExecutionTime = DateTime.UtcNow;

            // Actual Execution
            var result = await ExecuteNonQueryAsyncInternal(connection : connection,
                                                            commandText : commandText,
                                                            param : param,
                                                            commandType : commandType,
                                                            commandTimeout : commandTimeout,
                                                            transaction : transaction,
                                                            skipCommandArrayParametersCheck : true);

            // After Execution
            if (trace != null)
            {
                trace.AfterDelete(new TraceLog(commandText, param, result,
                                               DateTime.UtcNow.Subtract(beforeExecutionTime)));
            }

            // Result
            return(result);
        }