✨feat: Add CancellationToken support to all async methods#18
Merged
lukaferlez merged 3 commits intoApr 1, 2026
Merged
Conversation
Thread CancellationToken through the entire call chain from public interfaces down to Dapper CommandDefinition. All async operations now accept an optional cancellationToken parameter (default: default) and honour cancellation. Adds tests verifying that a pre-cancelled token throws OperationCanceledException. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Dapper.Contrib's DeleteAsync does not support CancellationToken. The single-model delete overloads always route to Dapper.Contrib and can never honour the token, so the parameter is removed. IEnumerable and filter-based delete variants are unaffected as they use bulk operations (SqlRepository path) that do support it. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Downgrade Microsoft.Data.SqlClient from 7.0.0 to 5.2.2 — v7 dropped .NET 6.0 support, causing SqlConnection.get_State() to throw NullReferenceException on the test project's net6.0 target. Forward CancellationToken through the entire BulkExtensions call chain: InsertBulkAsync/UpdateBulkAsync/DeleteBulkAsync -> ExecuteAsync<T,R> -> BulkSourceAsync -> TransferBulkAsync -> CreateTemporaryTableFromTable and ExecuteWithOutputMapAsync. Previously the token was accepted in every signature but silently dropped before reaching any Dapper CommandDefinition, so pre-cancelled tokens had no effect. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Owner
|
LGTM |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Body:
Summary
CancellationToken cancellationToken = defaultparameter to every async method across all interfaces (IAdd,IDelete,IUpdate,IUpsert,IReplace,IQueryGet,IQueryList,IQueryExist,IAggregate) and their Db-layer counterparts (IAddDb,IDeleteDb, etc.)CommandDefinition— the only way to pass a cancellation token in Dapper 2.0.xDbConnectionExtensions,DbRepository,Entity,ProjectedEntity,BulkExtensions,MergeExtensions,OutputMapExtensions,TruncateExtensions, andSqlConnectionExtensionsto forward thetoken at every level
Entity.ListAsync<T>updated to includeCancellationTokenin the method lookup type array and invocation argumentsTests
CancellationTokenTestswith 8 tests verifying that passing a pre-cancelledCancellationToken(canceled: true)causesOperationCanceledExceptionfor:ListAsync,GetAsync,AddAsync,UpdateAsync,DeleteAsync,ExistsAsync,DbRepository.QueryAsync,DbRepository.ExecuteAsyncTest plan
CancellationTokenTestsagainst a SQL Server instance to confirm all 8 tests pass