Dapper
Dapper copied to clipboard
Add CancellationToken support for MultiMap Queries.
Add overload methods for MultiMap queries to pass CancellationToken to CommandDefinition.
From this:
public static IEnumerable<TReturn> Query<TReturn>(this IDbConnection cnn, string sql, Type[] types, Func<object[], TReturn> map, object? param = null, IDbTransaction? transaction = null, bool buffered = true, string splitOn = "Id", int? commandTimeout = null, CommandType? commandType = null)
{
var command = new CommandDefinition(sql, param, transaction, commandTimeout, commandType, buffered ? CommandFlags.Buffered : CommandFlags.None);
var results = MultiMapImpl(cnn, command, types, map, splitOn, null, null, true);
return buffered ? results.ToList() : results;
}
To this:
public static IEnumerable<TReturn> Query<TReturn>(this IDbConnection cnn, string sql, Type[] types, Func<object[], TReturn> map, object? param = null, IDbTransaction? transaction = null, bool buffered = true, string splitOn = "Id", int? commandTimeout = null, CommandType? commandType = null, CancellationToken ct = CancellationToken.None)
{
var command = new CommandDefinition(sql, param, transaction, commandTimeout, commandType, buffered ? CommandFlags.Buffered : CommandFlags.None, ct);
var results = MultiMapImpl(cnn, command, types, map, splitOn, null, null, true);
return buffered ? results.ToList() : results;
}
EDIT:
Another aproach would be to give access to some private methods like:
MultiMapImpl
where we could manually build CommandDefinition with CancellationToken assigned to it.