ExecuteNonQueryAsync() public method

public ExecuteNonQueryAsync ( ) : Task
return Task
コード例 #1
0
        internal async Task ExecuteNonQueryHelperAsync(SqlCommand cmd)
        {
            DoPreExecute(cmd);
            await cmd.ExecuteNonQueryAsync().ConfigureAwait(false);

            OnExecutedCommand(cmd);
        }
コード例 #2
0
ファイル: NonQueryOperation.cs プロジェクト: frapid/frapid
        public virtual async Task NonQueryAsync(MapperDb db, DbCommand command)
        {
            var connection = db.GetConnection();
            if (connection == null)
            {
                throw new MapperException("Could not create database connection.");
            }

            await db.OpenSharedConnectionAsync().ConfigureAwait(false);
            command.Connection = connection;
            command.Transaction = db.GetTransaction();

            await command.ExecuteNonQueryAsync().ConfigureAwait(false);
        }
コード例 #3
0
ファイル: DbCommand.cs プロジェクト: vb-consulting/pgcode
 public static async ValueTask <int> ExecuteAsync(this System.Data.Common.DbCommand cmd, string command, CancellationToken cancellationToken = default)
 {
     cmd.CommandText = command;
     return(await cmd.ExecuteNonQueryAsync(cancellationToken));
 }
コード例 #4
0
        private async Task InsertInTransactionAsync(DbCommand sqlCommand, IEnumerable<JournalEntry> journalEntires)
        {
            using (var tx = _dbConnection.BeginTransaction())
            {
                sqlCommand.Transaction = tx;
                try
                {
                    foreach (var entry in journalEntires)
                    {
                        CopyParamsToCommand(sqlCommand, entry);

                        var commandResult = await sqlCommand.ExecuteNonQueryAsync();
                        if (commandResult != 1)
                        {
                            //TODO: something went wrong, ExecuteNonQuery() should return 1 (number of rows added)
                        }
                    }

                    tx.Commit();
                }
                catch (Exception)
                {
                    tx.Rollback();
                    throw;
                }
            }
        }
コード例 #5
0
        private async Task InsertInTransactionAsync(DbCommand sqlCommand, IEnumerable<JournalEntry> journalEntries)
        {
            using (var tx = sqlCommand.Connection.BeginTransaction())
            {
                sqlCommand.Transaction = tx;
                try
                {
                    foreach (var entry in journalEntries)
                    {
                        CopyParamsToCommand(sqlCommand, entry);

                        var result = await sqlCommand.ExecuteNonQueryAsync();
                        if (result != 1)
                        {
                            Log.Error("Persisted event operation was expected to return 1, but returned [{0}]", result);
                        }
                    }

                    tx.Commit();
                }
                catch (Exception)
                {
                    tx.Rollback();
                    throw;
                }
            }
        }
コード例 #6
0
ファイル: Database.cs プロジェクト: ChrisK91/CWSRestart
        /// <summary>
        /// Will execute the given command on the database asynchronously
        /// </summary>
        /// <param name="command">The command to execute</param>
        protected async void ExecuteCommandAsync(DbCommand command)
        {
            bool doClose = await InitializeConnectionAsync();
            initializeCommand(ref command);

            await command.ExecuteNonQueryAsync();

            if (doClose)
                Connection.Close();
        }
コード例 #7
0
        private async Task<int> DoExecuteNonQueryAsync(DbCommand command)
        {
            using (DbContext context = await DbContext.GetContextAsync(this.name))
            {
                command.Connection = context.Connection;

                DoDbEvent(command, DbEventType.BeforeExecution);

                int rowsAffected = await command.ExecuteNonQueryAsync();

                DoDbEvent(command, DbEventType.AfterExecution);

                return rowsAffected;
            }
        }