I'm using Dapper 1.31 from Nuget. I have this very simple code snippet,
string connString = "";
string query = "";
int val = 0;
CancellationTokenSource tokenSource = new CancellationTokenSource();
using (IDbConnection conn = new SqlConnection(connString))
{
conn.Open();
val = (await conn.QueryAsync<int>(query, tokenSource.Token)).FirstOrDefault();
}
When I press F12 on QueryAsync
, it points me to
public static Task<IEnumerable<T>> QueryAsync<T>
(
this IDbConnection cnn,
string sql,
dynamic param = null,
IDbTransaction transaction = null,
int? commandTimeout = null,
CommandType? commandType = null
);
There is no CancellationToken
on its signature.
Questions:
- Why is the snippet completely buildable assuming that there is no compiler error on the whole solution?
- Forgive me that I cannot test if calling
tokenSource.Cancel()
would really cancel the method because I don't know how to generate a long running sql query. Will the.Cancel()
really cancel the method and throwOperationCancelledException
?
Thank you!