diff --git a/Dapper/SqlMapper.Async.cs b/Dapper/SqlMapper.Async.cs
index 4b2ffe9db2a49d11504274de92689bbf88ddb7b0..01d62f4601aefcc19f7b8344fe8b2234fd13ff2e 100644
--- a/Dapper/SqlMapper.Async.cs
+++ b/Dapper/SqlMapper.Async.cs
@@ -16,94 +16,141 @@ public static partial class SqlMapper
///
/// Execute a query asynchronously using .NET 4.5 Task.
///
+ /// The connection to query on.
+ /// The SQL to execute for the query.
+ /// The parameters to pass, if any.
+ /// The transaction to use, if any.
+ /// The command timeout (in seconds).
+ /// The type of command to execute.
/// Note: each row can be accessed via "dynamic", or by casting to an IDictionary<string,object>
- public static Task> QueryAsync(this IDbConnection cnn, string sql, object param = null, IDbTransaction transaction = null, int? commandTimeout = null, CommandType? commandType = null)
- {
- return QueryAsync(cnn, typeof(DapperRow), new CommandDefinition(sql, param, transaction, commandTimeout, commandType, CommandFlags.Buffered, default(CancellationToken)));
- }
+ public static Task> QueryAsync(this IDbConnection cnn, string sql, object param = null, IDbTransaction transaction = null, int? commandTimeout = null, CommandType? commandType = null) =>
+ QueryAsync(cnn, typeof(DapperRow), new CommandDefinition(sql, param, transaction, commandTimeout, commandType, CommandFlags.Buffered, default(CancellationToken)));
///
/// Execute a query asynchronously using .NET 4.5 Task.
///
+ /// The connection to query on.
+ /// The command used to query on this connection.
/// Note: each row can be accessed via "dynamic", or by casting to an IDictionary<string,object>
- public static Task> QueryAsync(this IDbConnection cnn, CommandDefinition command)
- {
- return QueryAsync(cnn, typeof(DapperRow), command);
- }
+ public static Task> QueryAsync(this IDbConnection cnn, CommandDefinition command) =>
+ QueryAsync(cnn, typeof(DapperRow), command);
///
/// Execute a single-row query asynchronously using .NET 4.5 Task.
///
+ /// The connection to query on.
+ /// The command used to query on this connection.
/// Note: the row can be accessed via "dynamic", or by casting to an IDictionary<string,object>
- public static Task QueryFirstAsync(this IDbConnection cnn, CommandDefinition command)
- {
- return QueryRowAsync(cnn, Row.First, typeof(DapperRow), command);
- }
+ public static Task QueryFirstAsync(this IDbConnection cnn, CommandDefinition command) =>
+ QueryRowAsync(cnn, Row.First, typeof(DapperRow), command);
+
///
/// Execute a single-row query asynchronously using .NET 4.5 Task.
///
+ /// The connection to query on.
+ /// The command used to query on this connection.
/// Note: the row can be accessed via "dynamic", or by casting to an IDictionary<string,object>
- public static Task QueryFirstOrDefaultAsync(this IDbConnection cnn, CommandDefinition command)
- {
- return QueryRowAsync(cnn, Row.FirstOrDefault, typeof(DapperRow), command);
- }
+ public static Task QueryFirstOrDefaultAsync(this IDbConnection cnn, CommandDefinition command) =>
+ QueryRowAsync(cnn, Row.FirstOrDefault, typeof(DapperRow), command);
+
///
/// Execute a single-row query asynchronously using .NET 4.5 Task.
///
+ /// The connection to query on.
+ /// The command used to query on this connection.
/// Note: the row can be accessed via "dynamic", or by casting to an IDictionary<string,object>
- public static Task QuerySingleAsync(this IDbConnection cnn, CommandDefinition command)
- {
- return QueryRowAsync(cnn, Row.Single, typeof(DapperRow), command);
- }
+ public static Task QuerySingleAsync(this IDbConnection cnn, CommandDefinition command) =>
+ QueryRowAsync(cnn, Row.Single, typeof(DapperRow), command);
+
///
/// Execute a single-row query asynchronously using .NET 4.5 Task.
///
+ /// The connection to query on.
+ /// The command used to query on this connection.
/// Note: the row can be accessed via "dynamic", or by casting to an IDictionary<string,object>
- public static Task QuerySingleOrDefaultAsync(this IDbConnection cnn, CommandDefinition command)
- {
- return QueryRowAsync(cnn, Row.SingleOrDefault, typeof(DapperRow), command);
- }
+ public static Task QuerySingleOrDefaultAsync(this IDbConnection cnn, CommandDefinition command) =>
+ QueryRowAsync(cnn, Row.SingleOrDefault, typeof(DapperRow), command);
///
/// Execute a query asynchronously using .NET 4.5 Task.
///
- public static Task> QueryAsync(this IDbConnection cnn, string sql, object param = null, IDbTransaction transaction = null, int? commandTimeout = null, CommandType? commandType = null)
- {
- return QueryAsync(cnn, typeof(T), new CommandDefinition(sql, param, transaction, commandTimeout, commandType, CommandFlags.Buffered, default(CancellationToken)));
- }
+ /// The type of results to return.
+ /// The connection to query on.
+ /// The SQL to execute for the query.
+ /// The parameters to pass, if any.
+ /// The transaction to use, if any.
+ /// The command timeout (in seconds).
+ /// The type of command to execute.
+ ///
+ /// A sequence of data of ; if a basic type (int, string, etc) is queried then the data from the first column in assumed, otherwise an instance is
+ /// created per row, and a direct column-name===member-name mapping is assumed (case insensitive).
+ ///
+ public static Task> QueryAsync(this IDbConnection cnn, string sql, object param = null, IDbTransaction transaction = null, int? commandTimeout = null, CommandType? commandType = null) =>
+ QueryAsync(cnn, typeof(T), new CommandDefinition(sql, param, transaction, commandTimeout, commandType, CommandFlags.Buffered, default(CancellationToken)));
///
/// Execute a single-row query asynchronously using .NET 4.5 Task.
///
- public static Task QueryFirstAsync(this IDbConnection cnn, string sql, object param = null, IDbTransaction transaction = null, int? commandTimeout = null, CommandType? commandType = null)
- {
- return QueryRowAsync(cnn, Row.First, typeof(T), new CommandDefinition(sql, param, transaction, commandTimeout, commandType, CommandFlags.None, default(CancellationToken)));
- }
+ /// The type of result to return.
+ /// The connection to query on.
+ /// The SQL to execute for the query.
+ /// The parameters to pass, if any.
+ /// The transaction to use, if any.
+ /// The command timeout (in seconds).
+ /// The type of command to execute.
+ public static Task QueryFirstAsync(this IDbConnection cnn, string sql, object param = null, IDbTransaction transaction = null, int? commandTimeout = null, CommandType? commandType = null) =>
+ QueryRowAsync(cnn, Row.First, typeof(T), new CommandDefinition(sql, param, transaction, commandTimeout, commandType, CommandFlags.None, default(CancellationToken)));
+
///
/// Execute a single-row query asynchronously using .NET 4.5 Task.
///
- public static Task QueryFirstOrDefaultAsync(this IDbConnection cnn, string sql, object param = null, IDbTransaction transaction = null, int? commandTimeout = null, CommandType? commandType = null)
- {
- return QueryRowAsync(cnn, Row.FirstOrDefault, typeof(T), new CommandDefinition(sql, param, transaction, commandTimeout, commandType, CommandFlags.None, default(CancellationToken)));
- }
+ /// The type of result to return.
+ /// The connection to query on.
+ /// The SQL to execute for the query.
+ /// The parameters to pass, if any.
+ /// The transaction to use, if any.
+ /// The command timeout (in seconds).
+ /// The type of command to execute.
+ public static Task QueryFirstOrDefaultAsync(this IDbConnection cnn, string sql, object param = null, IDbTransaction transaction = null, int? commandTimeout = null, CommandType? commandType = null) =>
+ QueryRowAsync(cnn, Row.FirstOrDefault, typeof(T), new CommandDefinition(sql, param, transaction, commandTimeout, commandType, CommandFlags.None, default(CancellationToken)));
+
///
/// Execute a single-row query asynchronously using .NET 4.5 Task.
///
- public static Task QuerySingleAsync(this IDbConnection cnn, string sql, object param = null, IDbTransaction transaction = null, int? commandTimeout = null, CommandType? commandType = null)
- {
- return QueryRowAsync(cnn, Row.Single, typeof(T), new CommandDefinition(sql, param, transaction, commandTimeout, commandType, CommandFlags.None, default(CancellationToken)));
- }
+ /// The type of result to return.
+ /// The connection to query on.
+ /// The SQL to execute for the query.
+ /// The parameters to pass, if any.
+ /// The transaction to use, if any.
+ /// The command timeout (in seconds).
+ /// The type of command to execute.
+ public static Task QuerySingleAsync(this IDbConnection cnn, string sql, object param = null, IDbTransaction transaction = null, int? commandTimeout = null, CommandType? commandType = null) =>
+ QueryRowAsync(cnn, Row.Single, typeof(T), new CommandDefinition(sql, param, transaction, commandTimeout, commandType, CommandFlags.None, default(CancellationToken)));
+
///
/// Execute a single-row query asynchronously using .NET 4.5 Task.
///
- public static Task QuerySingleOrDefaultAsync(this IDbConnection cnn, string sql, object param = null, IDbTransaction transaction = null, int? commandTimeout = null, CommandType? commandType = null)
- {
- return QueryRowAsync(cnn, Row.SingleOrDefault, typeof(T), new CommandDefinition(sql, param, transaction, commandTimeout, commandType, CommandFlags.None, default(CancellationToken)));
- }
+ /// The type to return.
+ /// The connection to query on.
+ /// The SQL to execute for the query.
+ /// The parameters to pass, if any.
+ /// The transaction to use, if any.
+ /// The command timeout (in seconds).
+ /// The type of command to execute.
+ public static Task QuerySingleOrDefaultAsync(this IDbConnection cnn, string sql, object param = null, IDbTransaction transaction = null, int? commandTimeout = null, CommandType? commandType = null) =>
+ QueryRowAsync(cnn, Row.SingleOrDefault, typeof(T), new CommandDefinition(sql, param, transaction, commandTimeout, commandType, CommandFlags.None, default(CancellationToken)));
///
/// Execute a query asynchronously using .NET 4.5 Task.
///
+ /// The connection to query on.
+ /// The type to return.
+ /// The SQL to execute for the query.
+ /// The parameters to pass, if any.
+ /// The transaction to use, if any.
+ /// The command timeout (in seconds).
+ /// The type of command to execute.
+ /// is null .
public static Task> QueryAsync(this IDbConnection cnn, Type type, string sql, object param = null, IDbTransaction transaction = null, int? commandTimeout = null, CommandType? commandType = null)
{
if (type == null) throw new ArgumentNullException(nameof(type));
@@ -113,6 +160,14 @@ public static Task> QueryAsync(this IDbConnection cnn, Type
///
/// Execute a single-row query asynchronously using .NET 4.5 Task.
///
+ /// The connection to query on.
+ /// The type to return.
+ /// The SQL to execute for the query.
+ /// The parameters to pass, if any.
+ /// The transaction to use, if any.
+ /// The command timeout (in seconds).
+ /// The type of command to execute.
+ /// is null .
public static Task QueryFirstAsync(this IDbConnection cnn, Type type, string sql, object param = null, IDbTransaction transaction = null, int? commandTimeout = null, CommandType? commandType = null)
{
if (type == null) throw new ArgumentNullException(nameof(type));
@@ -121,6 +176,14 @@ public static Task QueryFirstAsync(this IDbConnection cnn, Type type, st
///
/// Execute a single-row query asynchronously using .NET 4.5 Task.
///
+ /// The connection to query on.
+ /// The type to return.
+ /// The SQL to execute for the query.
+ /// The parameters to pass, if any.
+ /// The transaction to use, if any.
+ /// The command timeout (in seconds).
+ /// The type of command to execute.
+ /// is null .
public static Task QueryFirstOrDefaultAsync(this IDbConnection cnn, Type type, string sql, object param = null, IDbTransaction transaction = null, int? commandTimeout = null, CommandType? commandType = null)
{
if (type == null) throw new ArgumentNullException(nameof(type));
@@ -129,6 +192,14 @@ public static Task QueryFirstOrDefaultAsync(this IDbConnection cnn, Type
///
/// Execute a single-row query asynchronously using .NET 4.5 Task.
///
+ /// The connection to query on.
+ /// The type to return.
+ /// The SQL to execute for the query.
+ /// The parameters to pass, if any.
+ /// The transaction to use, if any.
+ /// The command timeout (in seconds).
+ /// The type of command to execute.
+ /// is null .
public static Task QuerySingleAsync(this IDbConnection cnn, Type type, string sql, object param = null, IDbTransaction transaction = null, int? commandTimeout = null, CommandType? commandType = null)
{
if (type == null) throw new ArgumentNullException(nameof(type));
@@ -137,6 +208,14 @@ public static Task QuerySingleAsync(this IDbConnection cnn, Type type, s
///
/// Execute a single-row query asynchronously using .NET 4.5 Task.
///
+ /// The connection to query on.
+ /// The type to return.
+ /// The SQL to execute for the query.
+ /// The parameters to pass, if any.
+ /// The transaction to use, if any.
+ /// The command timeout (in seconds).
+ /// The type of command to execute.
+ /// is null .
public static Task QuerySingleOrDefaultAsync(this IDbConnection cnn, Type type, string sql, object param = null, IDbTransaction transaction = null, int? commandTimeout = null, CommandType? commandType = null)
{
if (type == null) throw new ArgumentNullException(nameof(type));
@@ -146,81 +225,103 @@ public static Task QuerySingleOrDefaultAsync(this IDbConnection cnn, Typ
///
/// Execute a query asynchronously using .NET 4.5 Task.
///
- public static Task> QueryAsync(this IDbConnection cnn, CommandDefinition command)
- {
- return QueryAsync(cnn, typeof(T), command);
- }
+ /// The type to return.
+ /// The connection to query on.
+ /// The command used to query on this connection.
+ ///
+ /// A sequence of data of ; if a basic type (int, string, etc) is queried then the data from the first column in assumed, otherwise an instance is
+ /// created per row, and a direct column-name===member-name mapping is assumed (case insensitive).
+ ///
+ public static Task> QueryAsync(this IDbConnection cnn, CommandDefinition command) =>
+ QueryAsync(cnn, typeof(T), command);
///
/// Execute a query asynchronously using .NET 4.5 Task.
///
- public static Task> QueryAsync(this IDbConnection cnn, Type type, CommandDefinition command)
- {
- return QueryAsync(cnn, type, command);
- }
+ /// The connection to query on.
+ /// The type to return.
+ /// The command used to query on this connection.
+ public static Task> QueryAsync(this IDbConnection cnn, Type type, CommandDefinition command) =>
+ QueryAsync(cnn, type, command);
+
///
/// Execute a single-row query asynchronously using .NET 4.5 Task.
///
- public static Task QueryFirstAsync(this IDbConnection cnn, Type type, CommandDefinition command)
- {
- return QueryRowAsync(cnn, Row.First, type, command);
- }
+ /// The connection to query on.
+ /// The type to return.
+ /// The command used to query on this connection.
+ public static Task QueryFirstAsync(this IDbConnection cnn, Type type, CommandDefinition command) =>
+ QueryRowAsync(cnn, Row.First, type, command);
+
///
/// Execute a single-row query asynchronously using .NET 4.5 Task.
///
- public static Task QueryFirstAsync(this IDbConnection cnn, CommandDefinition command)
- {
- return QueryRowAsync(cnn, Row.First, typeof(T), command);
- }
+ /// The type to return.
+ /// The connection to query on.
+ /// The command used to query on this connection.
+ public static Task QueryFirstAsync(this IDbConnection cnn, CommandDefinition command) =>
+ QueryRowAsync(cnn, Row.First, typeof(T), command);
+
///
/// Execute a single-row query asynchronously using .NET 4.5 Task.
///
- public static Task QueryFirstOrDefaultAsync(this IDbConnection cnn, Type type, CommandDefinition command)
- {
- return QueryRowAsync(cnn, Row.FirstOrDefault, type, command);
- }
+ /// The connection to query on.
+ /// The type to return.
+ /// The command used to query on this connection.
+ public static Task QueryFirstOrDefaultAsync(this IDbConnection cnn, Type type, CommandDefinition command) =>
+ QueryRowAsync(cnn, Row.FirstOrDefault, type, command);
+
///
/// Execute a single-row query asynchronously using .NET 4.5 Task.
///
- public static Task QueryFirstOrDefaultAsync(this IDbConnection cnn, CommandDefinition command)
- {
- return QueryRowAsync(cnn, Row.FirstOrDefault, typeof(T), command);
- }
+ /// The type to return.
+ /// The connection to query on.
+ /// The command used to query on this connection.
+ public static Task QueryFirstOrDefaultAsync(this IDbConnection cnn, CommandDefinition command) =>
+ QueryRowAsync(cnn, Row.FirstOrDefault, typeof(T), command);
+
///
/// Execute a single-row query asynchronously using .NET 4.5 Task.
///
- public static Task QuerySingleAsync(this IDbConnection cnn, Type type, CommandDefinition command)
- {
- return QueryRowAsync(cnn, Row.Single, type, command);
- }
+ /// The connection to query on.
+ /// The type to return.
+ /// The command used to query on this connection.
+ public static Task QuerySingleAsync(this IDbConnection cnn, Type type, CommandDefinition command) =>
+ QueryRowAsync(cnn, Row.Single, type, command);
+
///
/// Execute a single-row query asynchronously using .NET 4.5 Task.
///
- public static Task QuerySingleAsync(this IDbConnection cnn, CommandDefinition command)
- {
- return QueryRowAsync(cnn, Row.Single, typeof(T), command);
- }
+ /// The type to return.
+ /// The connection to query on.
+ /// The command used to query on this connection.
+ public static Task QuerySingleAsync(this IDbConnection cnn, CommandDefinition command) =>
+ QueryRowAsync(cnn, Row.Single, typeof(T), command);
+
///
/// Execute a single-row query asynchronously using .NET 4.5 Task.
///
- public static Task QuerySingleOrDefaultAsync(this IDbConnection cnn, Type type, CommandDefinition command)
- {
- return QueryRowAsync(cnn, Row.SingleOrDefault, type, command);
- }
+ /// The connection to query on.
+ /// The type to return.
+ /// The command used to query on this connection.
+ public static Task QuerySingleOrDefaultAsync(this IDbConnection cnn, Type type, CommandDefinition command) =>
+ QueryRowAsync(cnn, Row.SingleOrDefault, type, command);
+
///
/// Execute a single-row query asynchronously using .NET 4.5 Task.
///
- public static Task QuerySingleOrDefaultAsync(this IDbConnection cnn, CommandDefinition command)
- {
- return QueryRowAsync(cnn, Row.SingleOrDefault, typeof(T), command);
- }
+ /// The type to return.
+ /// The connection to query on.
+ /// The command used to query on this connection.
+ public static Task QuerySingleOrDefaultAsync(this IDbConnection cnn, CommandDefinition command) =>
+ QueryRowAsync(cnn, Row.SingleOrDefault, typeof(T), command);
private static Task ExecuteReaderWithFlagsFallbackAsync(DbCommand cmd, bool wasClosed, CommandBehavior behavior, CancellationToken cancellationToken)
{
var task = cmd.ExecuteReaderAsync(GetBehavior(wasClosed, behavior), cancellationToken);
if (task.Status == TaskStatus.Faulted && Settings.DisableCommandBehaviorOptimizations(behavior, task.Exception.InnerException))
{ // we can retry; this time it will have different flags
- task = cmd.ExecuteReaderAsync(GetBehavior(wasClosed, behavior), cancellationToken);
+ return cmd.ExecuteReaderAsync(GetBehavior(wasClosed, behavior), cancellationToken);
}
return task;
}
@@ -252,7 +353,7 @@ private static async Task> QueryAsync(this IDbConnection cnn,
if (command.Buffered)
{
- List buffer = new List();
+ var buffer = new List();
var convertToType = Nullable.GetUnderlyingType(effectiveType) ?? effectiveType;
while (await reader.ReadAsync(cancel).ConfigureAwait(false))
{
@@ -266,7 +367,7 @@ private static async Task> QueryAsync(this IDbConnection cnn,
buffer.Add((T)Convert.ChangeType(val, convertToType, CultureInfo.InvariantCulture));
}
}
- while (await reader.NextResultAsync(cancel).ConfigureAwait(false)) { }
+ while (await reader.NextResultAsync(cancel).ConfigureAwait(false)) { /* ignore subsequent result sets */ }
command.OnCompleted();
return buffer;
}
@@ -281,7 +382,7 @@ private static async Task> QueryAsync(this IDbConnection cnn,
}
finally
{
- using (reader) { } // dispose if non-null
+ using (reader) { /* dispose if non-null */ }
if (wasClosed) cnn.Close();
}
}
@@ -328,18 +429,18 @@ private static async Task QueryRowAsync(this IDbConnection cnn, Row row, T
result = (T)Convert.ChangeType(val, convertToType, CultureInfo.InvariantCulture);
}
if ((row & Row.Single) != 0 && await reader.ReadAsync(cancel).ConfigureAwait(false)) ThrowMultipleRows(row);
- while (await reader.ReadAsync(cancel).ConfigureAwait(false)) { }
+ while (await reader.ReadAsync(cancel).ConfigureAwait(false)) { /* ignore rows after the first */ }
}
else if ((row & Row.FirstOrDefault) == 0) // demanding a row, and don't have one
{
ThrowZeroRows(row);
}
- while (await reader.NextResultAsync(cancel).ConfigureAwait(false)) { }
+ while (await reader.NextResultAsync(cancel).ConfigureAwait(false)) { /* ignore result sets after the first */ }
return result;
}
finally
{
- using (reader) { } // dispose if non-null
+ using (reader) { /* dispose if non-null */ }
if (wasClosed) cnn.Close();
}
}
@@ -348,14 +449,22 @@ private static async Task QueryRowAsync(this IDbConnection cnn, Row row, T
///
/// Execute a command asynchronously using .NET 4.5 Task.
///
- public static Task ExecuteAsync(this IDbConnection cnn, string sql, object param = null, IDbTransaction transaction = null, int? commandTimeout = null, CommandType? commandType = null)
- {
- return ExecuteAsync(cnn, new CommandDefinition(sql, param, transaction, commandTimeout, commandType, CommandFlags.Buffered, default(CancellationToken)));
- }
+ /// The connection to query on.
+ /// The SQL to execute for this query.
+ /// The parameters to use for this query.
+ /// The transaction to use for this query.
+ /// Number of seconds before command execution timeout.
+ /// Is it a stored proc or a batch?
+ /// The number of rows affected.
+ public static Task ExecuteAsync(this IDbConnection cnn, string sql, object param = null, IDbTransaction transaction = null, int? commandTimeout = null, CommandType? commandType = null) =>
+ ExecuteAsync(cnn, new CommandDefinition(sql, param, transaction, commandTimeout, commandType, CommandFlags.Buffered, default(CancellationToken)));
///
/// Execute a command asynchronously using .NET 4.5 Task.
///
+ /// The connection to execute on.
+ /// The command to execute on this connection.
+ /// The number of rows affected.
public static Task ExecuteAsync(this IDbConnection cnn, CommandDefinition command)
{
object param = command.Parameters;
@@ -429,16 +538,17 @@ private static async Task ExecuteMultiImplAsync(IDbConnection cnn, CommandD
while (pending.Count != 0)
{
var pair = pending.Dequeue();
- using (pair.Command) { } // dispose commands
+ using (pair.Command) { /* dispose commands */ }
total += await pair.Task.ConfigureAwait(false);
}
- } finally
+ }
+ finally
{
// this only has interesting work to do if there are failures
- using (cmd) { } // dispose commands
+ using (cmd) { /* dispose commands */ }
while (pending.Count != 0)
{ // dispose tasks even in failure
- using (pending.Dequeue().Command) { } // dispose commands
+ using (pending.Dequeue().Command) { /* dispose commands */ }
}
}
}
@@ -497,175 +607,250 @@ private static async Task ExecuteImplAsync(IDbConnection cnn, CommandDefini
}
///
- /// Maps a query to objects
+ /// Perform a asynchronous multi-mapping query with 2 input types.
+ /// This returns a single type, combined from the raw types via .
///
- /// The first type in the recordset
- /// The second type in the recordset
- /// The return type
- ///
- ///
- ///
- ///
- ///
- ///
- /// The field we should split and read the second object from (default: id)
- /// Number of seconds before command execution timeout
+ /// The first type in the recordset.
+ /// The second type in the recordset.
+ /// The combined type to return.
+ /// The connection to query on.
+ /// The SQL to execute for this query.
+ /// The function to map row types to the return type.
+ /// The parameters to use for this query.
+ /// The transaction to use for this query.
+ /// Whether to buffer the results in memory.
+ /// The field we should split and read the second object from (default: "Id").
+ /// Number of seconds before command execution timeout.
/// Is it a stored proc or a batch?
- ///
- public static Task> QueryAsync(this IDbConnection cnn, string sql, Func map, object param = null, IDbTransaction transaction = null, bool buffered = true, string splitOn = "Id", int? commandTimeout = null, CommandType? commandType = null)
- {
- return MultiMapAsync(cnn,
+ /// An enumerable of .
+ public static Task> QueryAsync(this IDbConnection cnn, string sql, Func map, object param = null, IDbTransaction transaction = null, bool buffered = true, string splitOn = "Id", int? commandTimeout = null, CommandType? commandType = null) =>
+ MultiMapAsync(cnn,
new CommandDefinition(sql, param, transaction, commandTimeout, commandType, buffered ? CommandFlags.Buffered : CommandFlags.None, default(CancellationToken)), map, splitOn);
- }
///
- /// Maps a query to objects
+ /// Perform a asynchronous multi-mapping query with 2 input types.
+ /// This returns a single type, combined from the raw types via .
///
- /// The first type in the recordset
- /// The second type in the recordset
- /// The return type
- ///
- /// The field we should split and read the second object from (default: id)
- /// The command to execute
- ///
- ///
- public static Task> QueryAsync(this IDbConnection cnn, CommandDefinition command, Func map, string splitOn = "Id")
- {
- return MultiMapAsync(cnn, command, map, splitOn);
- }
+ /// The first type in the recordset.
+ /// The second type in the recordset.
+ /// The combined type to return.
+ /// The connection to query on.
+ /// The field we should split and read the second object from (default: "Id").
+ /// The command to execute.
+ /// The function to map row types to the return type.
+ /// An enumerable of .
+ public static Task> QueryAsync(this IDbConnection cnn, CommandDefinition command, Func map, string splitOn = "Id") =>
+ MultiMapAsync(cnn, command, map, splitOn);
///
- /// Maps a query to objects
- ///
- ///
- ///
- ///
- ///
- ///
- ///
- ///
- ///
- ///
- ///
- /// The Field we should split and read the second object from (default: id)
- /// Number of seconds before command execution timeout
- ///
- ///
- public static Task> QueryAsync(this IDbConnection cnn, string sql, Func map, object param = null, IDbTransaction transaction = null, bool buffered = true, string splitOn = "Id", int? commandTimeout = null, CommandType? commandType = null)
- {
- return MultiMapAsync(cnn,
+ /// Perform a asynchronous multi-mapping query with 3 input types.
+ /// This returns a single type, combined from the raw types via .
+ ///
+ /// The first type in the recordset.
+ /// The second type in the recordset.
+ /// The third type in the recordset.
+ /// The combined type to return.
+ /// The connection to query on.
+ /// The SQL to execute for this query.
+ /// The function to map row types to the return type.
+ /// The parameters to use for this query.
+ /// The transaction to use for this query.
+ /// Whether to buffer the results in memory.
+ /// The field we should split and read the second object from (default: "Id").
+ /// Number of seconds before command execution timeout.
+ /// Is it a stored proc or a batch?
+ /// An enumerable of .
+ public static Task> QueryAsync(this IDbConnection cnn, string sql, Func map, object param = null, IDbTransaction transaction = null, bool buffered = true, string splitOn = "Id", int? commandTimeout = null, CommandType? commandType = null) =>
+ MultiMapAsync(cnn,
new CommandDefinition(sql, param, transaction, commandTimeout, commandType, buffered ? CommandFlags.Buffered : CommandFlags.None, default(CancellationToken)), map, splitOn);
- }
///
- /// Maps a query to objects
+ /// Perform a asynchronous multi-mapping query with 3 input types.
+ /// This returns a single type, combined from the raw types via .
///
- ///
- ///
- ///
- ///
- ///
- /// The field we should split and read the second object from (default: id)
- /// The command to execute
- ///
- ///
- public static Task> QueryAsync(this IDbConnection cnn, CommandDefinition command, Func map, string splitOn = "Id")
- {
- return MultiMapAsync(cnn, command, map, splitOn);
- }
+ /// The first type in the recordset.
+ /// The second type in the recordset.
+ /// The third type in the recordset.
+ /// The combined type to return.
+ /// The connection to query on.
+ /// The field we should split and read the second object from (default: "Id").
+ /// The command to execute.
+ /// The function to map row types to the return type.
+ /// An enumerable of .
+ public static Task> QueryAsync(this IDbConnection cnn, CommandDefinition command, Func map, string splitOn = "Id") =>
+ MultiMapAsync(cnn, command, map, splitOn);
///
- /// Perform a multi mapping query with 4 input parameters
- ///
- ///
- ///
- ///
- ///
- ///
- ///
- ///
- ///
- ///
- ///
- ///
- ///
- ///
- ///
- ///
- public static Task> QueryAsync(this IDbConnection cnn, string sql, Func map, object param = null, IDbTransaction transaction = null, bool buffered = true, string splitOn = "Id", int? commandTimeout = null, CommandType? commandType = null)
- {
- return MultiMapAsync(cnn,
+ /// Perform a asynchronous multi-mapping query with 4 input types.
+ /// This returns a single type, combined from the raw types via .
+ ///
+ /// The first type in the recordset.
+ /// The second type in the recordset.
+ /// The third type in the recordset.
+ /// The fourth type in the recordset.
+ /// The combined type to return.
+ /// The connection to query on.
+ /// The SQL to execute for this query.
+ /// The function to map row types to the return type.
+ /// The parameters to use for this query.
+ /// The transaction to use for this query.
+ /// Whether to buffer the results in memory.
+ /// The field we should split and read the second object from (default: "Id").
+ /// Number of seconds before command execution timeout.
+ /// Is it a stored proc or a batch?
+ /// An enumerable of .
+ public static Task> QueryAsync(this IDbConnection cnn, string sql, Func map, object param = null, IDbTransaction transaction = null, bool buffered = true, string splitOn = "Id", int? commandTimeout = null, CommandType? commandType = null) =>
+ MultiMapAsync(cnn,
new CommandDefinition(sql, param, transaction, commandTimeout, commandType, buffered ? CommandFlags.Buffered : CommandFlags.None, default(CancellationToken)), map, splitOn);
- }
///
- /// Perform a multi mapping query with 4 input parameters
+ /// Perform a asynchronous multi-mapping query with 4 input types.
+ /// This returns a single type, combined from the raw types via .
///
- ///
- ///
- ///
- ///
- ///
- ///
- /// The field we should split and read the second object from (default: id)
- /// The command to execute
- ///
- ///
- public static Task> QueryAsync(this IDbConnection cnn, CommandDefinition command, Func map, string splitOn = "Id")
- {
- return MultiMapAsync(cnn, command, map, splitOn);
- }
+ /// The first type in the recordset.
+ /// The second type in the recordset.
+ /// The third type in the recordset.
+ /// The fourth type in the recordset.
+ /// The combined type to return.
+ /// The connection to query on.
+ /// The field we should split and read the second object from (default: "Id").
+ /// The command to execute.
+ /// The function to map row types to the return type.
+ /// An enumerable of .
+ public static Task> QueryAsync(this IDbConnection cnn, CommandDefinition command, Func map, string splitOn = "Id") =>
+ MultiMapAsync(cnn, command, map, splitOn);
///
- /// Perform a multi mapping query with 5 input parameters
+ /// Perform a asynchronous multi-mapping query with 5 input types.
+ /// This returns a single type, combined from the raw types via .
///
- public static Task> QueryAsync(this IDbConnection cnn, string sql, Func map, object param = null, IDbTransaction transaction = null, bool buffered = true, string splitOn = "Id", int? commandTimeout = null, CommandType? commandType = null)
- {
- return MultiMapAsync(cnn,
+ /// The first type in the recordset.
+ /// The second type in the recordset.
+ /// The third type in the recordset.
+ /// The fourth type in the recordset.
+ /// The fifth type in the recordset.
+ /// The combined type to return.
+ /// The connection to query on.
+ /// The SQL to execute for this query.
+ /// The function to map row types to the return type.
+ /// The parameters to use for this query.
+ /// The transaction to use for this query.
+ /// Whether to buffer the results in memory.
+ /// The field we should split and read the second object from (default: "Id").
+ /// Number of seconds before command execution timeout.
+ /// Is it a stored proc or a batch?
+ /// An enumerable of .
+ public static Task> QueryAsync(this IDbConnection cnn, string sql, Func map, object param = null, IDbTransaction transaction = null, bool buffered = true, string splitOn = "Id", int? commandTimeout = null, CommandType? commandType = null) =>
+ MultiMapAsync(cnn,
new CommandDefinition(sql, param, transaction, commandTimeout, commandType, buffered ? CommandFlags.Buffered : CommandFlags.None, default(CancellationToken)), map, splitOn);
- }
///
- /// Perform a multi mapping query with 5 input parameters
+ /// Perform a asynchronous multi-mapping query with 5 input types.
+ /// This returns a single type, combined from the raw types via .
///
- public static Task> QueryAsync(this IDbConnection cnn, CommandDefinition command, Func map, string splitOn = "Id")
- {
- return MultiMapAsync(cnn, command, map, splitOn);
- }
+ /// The first type in the recordset.
+ /// The second type in the recordset.
+ /// The third type in the recordset.
+ /// The fourth type in the recordset.
+ /// The fifth type in the recordset.
+ /// The combined type to return.
+ /// The connection to query on.
+ /// The field we should split and read the second object from (default: "Id").
+ /// The command to execute.
+ /// The function to map row types to the return type.
+ /// An enumerable of .
+ public static Task> QueryAsync(this IDbConnection cnn, CommandDefinition command, Func map, string splitOn = "Id") =>
+ MultiMapAsync(cnn, command, map, splitOn);
///
- /// Perform a multi mapping query with 6 input parameters
+ /// Perform a asynchronous multi-mapping query with 6 input types.
+ /// This returns a single type, combined from the raw types via .
///
- public static Task> QueryAsync(this IDbConnection cnn, string sql, Func map, object param = null, IDbTransaction transaction = null, bool buffered = true, string splitOn = "Id", int? commandTimeout = null, CommandType? commandType = null)
- {
- return MultiMapAsync(cnn,
+ /// The first type in the recordset.
+ /// The second type in the recordset.
+ /// The third type in the recordset.
+ /// The fourth type in the recordset.
+ /// The fifth type in the recordset.
+ /// The sixth type in the recordset.
+ /// The combined type to return.
+ /// The connection to query on.
+ /// The SQL to execute for this query.
+ /// The function to map row types to the return type.
+ /// The parameters to use for this query.
+ /// The transaction to use for this query.
+ /// Whether to buffer the results in memory.
+ /// The field we should split and read the second object from (default: "Id").
+ /// Number of seconds before command execution timeout.
+ /// Is it a stored proc or a batch?
+ /// An enumerable of .
+ public static Task> QueryAsync(this IDbConnection cnn, string sql, Func map, object param = null, IDbTransaction transaction = null, bool buffered = true, string splitOn = "Id", int? commandTimeout = null, CommandType? commandType = null) =>
+ MultiMapAsync(cnn,
new CommandDefinition(sql, param, transaction, commandTimeout, commandType, buffered ? CommandFlags.Buffered : CommandFlags.None, default(CancellationToken)), map, splitOn);
- }
///
- /// Perform a multi mapping query with 6 input parameters
+ /// Perform a asynchronous multi-mapping query with 6 input types.
+ /// This returns a single type, combined from the raw types via .
///
- public static Task> QueryAsync(this IDbConnection cnn, CommandDefinition command, Func map, string splitOn = "Id")
- {
- return MultiMapAsync(cnn, command, map, splitOn);
- }
+ /// The first type in the recordset.
+ /// The second type in the recordset.
+ /// The third type in the recordset.
+ /// The fourth type in the recordset.
+ /// The fifth type in the recordset.
+ /// The sixth type in the recordset.
+ /// The combined type to return.
+ /// The connection to query on.
+ /// The field we should split and read the second object from (default: "Id").
+ /// The command to execute.
+ /// The function to map row types to the return type.
+ /// An enumerable of .
+ public static Task> QueryAsync(this IDbConnection cnn, CommandDefinition command, Func map, string splitOn = "Id") =>
+ MultiMapAsync(cnn, command, map, splitOn);
///
- /// Perform a multi mapping query with 7 input parameters
+ /// Perform a asynchronous multi-mapping query with 7 input types.
+ /// This returns a single type, combined from the raw types via .
///
- public static Task> QueryAsync(this IDbConnection cnn, string sql, Func map, object param = null, IDbTransaction transaction = null, bool buffered = true, string splitOn = "Id", int? commandTimeout = null, CommandType? commandType = null)
- {
- return MultiMapAsync(cnn,
+ /// The first type in the recordset.
+ /// The second type in the recordset.
+ /// The third type in the recordset.
+ /// The fourth type in the recordset.
+ /// The fifth type in the recordset.
+ /// The sixth type in the recordset.
+ /// The seventh type in the recordset.
+ /// The combined type to return.
+ /// The connection to query on.
+ /// The SQL to execute for this query.
+ /// The function to map row types to the return type.
+ /// The parameters to use for this query.
+ /// The transaction to use for this query.
+ /// Whether to buffer the results in memory.
+ /// The field we should split and read the second object from (default: "Id").
+ /// Number of seconds before command execution timeout.
+ /// Is it a stored proc or a batch?
+ /// An enumerable of .
+ public static Task> QueryAsync(this IDbConnection cnn, string sql, Func map, object param = null, IDbTransaction transaction = null, bool buffered = true, string splitOn = "Id", int? commandTimeout = null, CommandType? commandType = null) =>
+ MultiMapAsync(cnn,
new CommandDefinition(sql, param, transaction, commandTimeout, commandType, buffered ? CommandFlags.Buffered : CommandFlags.None, default(CancellationToken)), map, splitOn);
- }
///
- /// Perform a multi mapping query with 7 input parameters
+ /// Perform an asynchronous multi-mapping query with 7 input types.
+ /// This returns a single type, combined from the raw types via .
///
- public static Task> QueryAsync(this IDbConnection cnn, CommandDefinition command, Func map, string splitOn = "Id")
- {
- return MultiMapAsync(cnn, command, map, splitOn);
- }
+ /// The first type in the recordset.
+ /// The second type in the recordset.
+ /// The third type in the recordset.
+ /// The fourth type in the recordset.
+ /// The fifth type in the recordset.
+ /// The sixth type in the recordset.
+ /// The seventh type in the recordset.
+ /// The combined type to return.
+ /// The connection to query on.
+ /// The field we should split and read the second object from (default: "Id").
+ /// The command to execute.
+ /// The function to map row types to the return type.
+ /// An enumerable of .
+ public static Task> QueryAsync(this IDbConnection cnn, CommandDefinition command, Func map, string splitOn = "Id") =>
+ MultiMapAsync(cnn, command, map, splitOn);
private static async Task> MultiMapAsync(this IDbConnection cnn, CommandDefinition command, Delegate map, string splitOn)
{
@@ -683,31 +868,33 @@ private static async Task ExecuteImplAsync(IDbConnection cnn, CommandDefini
var results = MultiMapImpl(null, CommandDefinition.ForCallback(command.Parameters), map, splitOn, reader, identity, true);
return command.Buffered ? results.ToList() : results;
}
- } finally
+ }
+ finally
{
if (wasClosed) cnn.Close();
}
}
///
- /// Perform a multi mapping query with arbitrary input parameters
+ /// Perform a asynchronous multi-mapping query with an arbitrary number of input types.
+ /// This returns a single type, combined from the raw types via .
///
- /// The return type
- ///
- ///
- /// array of types in the recordset
- ///
- ///
- ///
- ///
- /// The Field we should split and read the second object from (default: id)
- /// Number of seconds before command execution timeout
+ /// The combined type to return.
+ /// The connection to query on.
+ /// The SQL to execute for this query.
+ /// Array of types in the recordset.
+ /// The function to map row types to the return type.
+ /// The parameters to use for this query.
+ /// The transaction to use for this query.
+ /// Whether to buffer the results in memory.
+ /// The field we should split and read the second object from (default: "Id").
+ /// Number of seconds before command execution timeout.
/// Is it a stored proc or a batch?
- ///
+ /// An enumerable of .
public static Task> QueryAsync(this IDbConnection cnn, string sql, Type[] types, Func 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, default(CancellationToken));
- return MultiMapAsync(cnn, command, types, map, splitOn);
+ return MultiMapAsync(cnn, command, types, map, splitOn);
}
private static async Task> MultiMapAsync(this IDbConnection cnn, CommandDefinition command, Type[] types, Func map, string splitOn)
@@ -725,7 +912,7 @@ private static async Task> MultiMapAsync(this IDbC
if (wasClosed) await ((DbConnection)cnn).OpenAsync().ConfigureAwait(false);
using (var cmd = (DbCommand)command.SetupCommand(cnn, info.ParamReader))
using (var reader = await ExecuteReaderWithFlagsFallbackAsync(cmd, wasClosed, CommandBehavior.SequentialAccess | CommandBehavior.SingleResult, command.CancellationToken).ConfigureAwait(false)) {
- var results = MultiMapImpl(null, default(CommandDefinition), types, map, splitOn, reader, identity, true);
+ var results = MultiMapImpl(null, default(CommandDefinition), types, map, splitOn, reader, identity, true);
return command.Buffered ? results.ToList() : results;
}
}
@@ -742,29 +929,32 @@ private static IEnumerable ExecuteReaderSync(IDataReader reader, Func
- /// Execute a command that returns multiple result sets, and access each in turn
+ /// Execute a command that returns multiple result sets, and access each in turn.
///
- public static Task QueryMultipleAsync(
- this IDbConnection cnn, string sql, object param = null, IDbTransaction transaction = null, int? commandTimeout = null, CommandType? commandType = null
- )
- {
- var command = new CommandDefinition(sql, param, transaction, commandTimeout, commandType, CommandFlags.Buffered);
- return QueryMultipleAsync(cnn, command);
- }
+ /// The connection to query on.
+ /// The SQL to execute for this query.
+ /// The parameters to use for this query.
+ /// The transaction to use for this query.
+ /// Number of seconds before command execution timeout.
+ /// Is it a stored proc or a batch?
+ public static Task QueryMultipleAsync(this IDbConnection cnn, string sql, object param = null, IDbTransaction transaction = null, int? commandTimeout = null, CommandType? commandType = null) =>
+ QueryMultipleAsync(cnn, new CommandDefinition(sql, param, transaction, commandTimeout, commandType, CommandFlags.Buffered));
///
- /// Execute a command that returns multiple result sets, and access each in turn
+ /// Execute a command that returns multiple result sets, and access each in turn.
///
+ /// The connection to query on.
+ /// The command to execute for this query.
public static async Task QueryMultipleAsync(this IDbConnection cnn, CommandDefinition command)
{
object param = command.Parameters;
- Identity identity = new Identity(command.CommandText, command.CommandType, cnn, typeof(GridReader), param?.GetType(), null);
+ var identity = new Identity(command.CommandText, command.CommandType, cnn, typeof(GridReader), param?.GetType(), null);
CacheInfo info = GetCacheInfo(identity, param, command.AddToCache);
DbCommand cmd = null;
@@ -790,7 +980,8 @@ public static async Task QueryMultipleAsync(this IDbConnection cnn,
if (!reader.IsClosed)
{
try { cmd.Cancel(); }
- catch { /* don't spoil the existing exception */ }
+ catch { /* don't spoil the existing exception */
+ }
}
reader.Dispose();
}
@@ -801,8 +992,14 @@ public static async Task QueryMultipleAsync(this IDbConnection cnn,
}
///
- /// Execute parameterized SQL and return an
+ /// Execute parameterized SQL and return an .
///
+ /// The connection to execute on.
+ /// The SQL to execute.
+ /// The parameters to use for this command.
+ /// The transaction to use for this command.
+ /// Number of seconds before command execution timeout.
+ /// Is it a stored proc or a batch?
/// An that can be used to iterate over the results of the SQL query.
///
/// This is typically used when the results of a query are not processed by Dapper, for example, used to fill a
@@ -819,26 +1016,21 @@ public static async Task QueryMultipleAsync(this IDbConnection cnn,
/// ]]>
///
///
- public static Task ExecuteReaderAsync(
- this IDbConnection cnn, string sql, object param = null, IDbTransaction transaction = null, int? commandTimeout = null, CommandType? commandType = null
- )
- {
- var command = new CommandDefinition(sql, param, transaction, commandTimeout, commandType, CommandFlags.Buffered);
- return ExecuteReaderImplAsync(cnn, command);
- }
+ public static Task