Пример #1
0
        /// <summary>
        /// Executes the update statement with Dapper, using the provided database connection.
        /// </summary>
        /// <param name="connection">The database connection.</param>
        /// <param name="transaction">The transaction to execute under (optional).</param>
        /// <param name="options">The options for the command (optional).</param>
        public int Execute(IDbConnection connection, IDbTransaction transaction = null, SqlMapperOptions options = null)
        {
            if (options == null)
            {
                options = SqlMapperOptions.DefaultOptions;
            }

            var result = connection.Execute(BuildSql(), Parameters, transaction, options.CommandTimeout, options.CommandType);

            return(result);
        }
Пример #2
0
        /// <summary>
        /// Executes the DELETE statement with Dapper asynchronously, using the provided database connection.
        /// </summary>
        /// <param name="connection">The database connection.</param>
        /// <param name="transaction">The transaction to execute under (optional).</param>
        /// <param name="options">The options for the command (optional).</param>
        public async Task <int> ExecuteAsync(IDbConnection connection, IDbTransaction transaction = null, SqlMapperOptions options = null)
        {
            if (options == null)
            {
                options = SqlMapperOptions.DefaultOptions;
            }

            int result = await connection.ExecuteAsync(BuildSql(), Parameters, transaction, options.CommandTimeout, options.CommandType);

            if (Deletes != null)
            {
                // Execute each delete and aggregate the results
                result = await Deletes.AggregateAsync(result, async (current, delete) => current + await delete.ExecuteAsync(connection, transaction, options));
            }
            return(result);
        }