QueryAsync with custom mapping AND CancellationToken
I want to use QueryAsync with multiple types mapped onto a single return type WITH a cancellation token but none of the QueryAsync functions allow for that.
My current solution is to use the private MultiMapAsync method but this is not ideal and I don't know what the right solution to this would be but I'd like to talk about it and if you're down I can make a pull request.
Maybe relevant?
no because that one doesnt do multi mapping
I think we use multi mapping in a similar way. Let me see
protected CommandDefinition CompileQuery(Query query, IDbTransaction transaction,
CancellationToken token, CommandFlags flags = CommandFlags.Buffered)
{
var statement = _compiler.Compile(query).ToString();
return new CommandDefinition(statement, transaction:transaction,
cancellationToken:token, flags:flags);
}
protected async Task<IEnumerable<TEntity>> QueryAsync<TFirst, TSecond>(Query query, IDbTransaction transaction, CancellationToken token,
Func<TFirst, TSecond, TEntity> map, string splitOn = "id")
where TFirst: new() where TSecond: new()
{
var command = CompileQuery(query, transaction, token, CommandFlags.Buffered);
return await transaction.Connection!.QueryAsync<TFirst, TSecond>(command, map, splitOn).ConfigureAwait(false);
}
But I might be missing something.
this is for a static number of objects in the result i want dynamic number of objects in the result and cancellation token
i want dynamic number of objects in the result and cancellation token
It could be helpful if you point us to the signature which is missing the CommandDefinition parameter?
public static Task<IEnumerable<TReturn>> QueryAsync<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)
this one
i want this to be public because ^^ just wraps all the parameters into a command definition and calls this:
private static async Task<IEnumerable<TReturn>> MultiMapAsync<TReturn>(this IDbConnection cnn, CommandDefinition command, Type[] types, Func<object[], TReturn> map, string splitOn)
Hi, I've ran into the same use case. Is there really no way of passing a CancellationToken when using custom mapping?