/// <summary> /// Executes a database statement asynchronously. /// </summary> /// <param name="callback">The callback method.</param> /// <param name="userState">The user state.</param> /// <returns>The asynchronous result.</returns> public abstract IAsyncResult ExecuteNonQuery(DbCommandNonQueryCallback callback, object userState = null);
/// <summary> /// Executes a database statement asynchronously. /// </summary> /// <param name="callback">The callback method.</param> /// <param name="userState">The user state.</param> /// <returns>The asynchronous result.</returns> public override IAsyncResult ExecuteNonQuery(DbCommandNonQueryCallback callback, object userState = null) { // Create the asynchronous result. DbAsyncResult asyncResult = new DbAsyncResult(userState); // Begin execute the command asynchronously. this.command.BeginExecuteNonQuery((IAsyncResult result) => { // Set the synchronous completion of the command. asyncResult.CompletedSynchronously = result.CompletedSynchronously; int count = 0; try { count = this.command.EndExecuteNonQuery(result); } catch (Exception exception) { // If an exception occurs, set the exception. asyncResult.Exception = new DbException("The execution of the SQL statement \'{0}\' failed.".FormatWith(this.Query), exception); } // Complete the asynchronous operation. asyncResult.Complete(); // Call the callback method. if (callback != null) callback(asyncResult, count); }, asyncResult.AsyncState); return asyncResult; }