diff --git a/Examples/Examples.csproj b/Examples/Examples.csproj new file mode 100644 index 0000000..a76ec1f --- /dev/null +++ b/Examples/Examples.csproj @@ -0,0 +1,11 @@ + + + + netstandard2.0 + + + + + + + diff --git a/Examples/Transaction.cs b/Examples/Transaction.cs new file mode 100644 index 0000000..5f32317 --- /dev/null +++ b/Examples/Transaction.cs @@ -0,0 +1,30 @@ +using Open.Database.Extensions; +using System.Data.SqlClient; + +public static partial class Examples +{ + public readonly static DbConnectionFactory ConnectionFactory + = new DbConnectionFactory(()=>new SqlConnection()); + + // Returns true if the transaction is successful. + public static bool TryTransaction() + => ConnectionFactory.Using(connection => + // Open a connection and start a transaction. + connection.ExecuteTransactionConditional(transaction => { + + // First procedure does some updates. + var count = transaction + .StoredProcedure("[Updated Procedure]") + .ExecuteNonQuery(); + + // Second procedure validates the results. + // If it returns true, then the transaction is commited. + // If it returns false, then the transaction is rolled back. + return transaction + .StoredProcedure("[Validation Procedure]") + .AddParam("@ExpectedCount", count) + .ExecuteScalar(); + })); + +} + diff --git a/ExpressiveCommandBase.cs b/ExpressiveCommandBase.cs index fd5df87..d75bf0d 100644 --- a/ExpressiveCommandBase.cs +++ b/ExpressiveCommandBase.cs @@ -31,14 +31,19 @@ public abstract partial class ExpressiveCommandBase protected readonly TConnection Connection; + /// + /// The transaction to execute commands on if not using a connection factory. + /// + protected readonly IDbTransaction Transaction; + ExpressiveCommandBase( CommandType type, string command, - List @params = null) + IEnumerable @params) { Type = type; Command = command ?? throw new ArgumentNullException(nameof(command)); - Params = @params ?? throw new ArgumentNullException(nameof(@params)); + Params = @params?.ToList() ?? new List(); Timeout = CommandTimeout.DEFAULT_SECONDS; } @@ -50,25 +55,28 @@ protected ExpressiveCommandBase( IDbConnectionFactory connFactory, CommandType type, string command, - List @params) - : this(type, command, @params ?? new List()) + IEnumerable @params) + : this(type, command, @params) { ConnectionFactory = connFactory ?? throw new ArgumentNullException(nameof(connFactory)); } - /// The connection to execute the command on. - /// The command type>. - /// The SQL command. - /// The list of params - protected ExpressiveCommandBase( + /// The connection to execute the command on. + /// The optional transaction to execute the command on. + /// The command type>. + /// The SQL command. + /// The list of params + protected ExpressiveCommandBase( TConnection connection, + IDbTransaction transaction, CommandType type, string command, - List @params) - : this(type, command, @params ?? new List()) + IEnumerable @params) + : this(type, command, @params) { Connection = connection ?? throw new ArgumentNullException(nameof(connection)); - } + Transaction = transaction; + } /// /// The command text or procedure name to use. @@ -252,36 +260,36 @@ public TThis SetTimeout(ushort seconds) /// Handles providing the connection for use with the command. /// /// The handler for use with the connection. - protected void UsingConnection(Action action) + protected void UsingConnection(Action action) { - if (ConnectionFactory != null) - { - using (var conn = ConnectionFactory.Create()) - { - action(conn); - } - } - else - { - action(Connection); - } - } + if (Connection != null) + { + action(Connection, Transaction); + } + else + { + using (var conn = ConnectionFactory.Create()) + { + action(conn, null); + } + } + } /// /// Handles providing the connection for use with the command. /// /// The handler for use with the connection. - protected T UsingConnection(Func action) + protected T UsingConnection(Func action) { if (Connection != null) { - return action(Connection); + return action(Connection, Transaction); } else { using (var conn = ConnectionFactory.Create()) { - return action(conn); + return action(conn, null); } } } @@ -291,13 +299,14 @@ protected T UsingConnection(Func action) /// /// The handler function for each IDataRecord. public void Execute(Action handler) - => UsingConnection(con => + => UsingConnection((con,t) => { using (var cmd = con.CreateCommand(Type, Command, Timeout)) { var c = cmd as TCommand; if (c == null) throw new InvalidCastException($"Actual command type ({cmd.GetType()}) is not compatible with expected command type ({typeof(TCommand)})."); - AddParams(c); + if (t != null) c.Transaction = t; + AddParams(c); con.EnsureOpen(); handler(c); } @@ -311,13 +320,14 @@ public void Execute(Action handler) /// The transform function for each IDataRecord. /// The result of the transform. public T Execute(Func transform) - => UsingConnection(con => + => UsingConnection((con,t) => { using (var cmd = con.CreateCommand(Type, Command, Timeout)) { var c = cmd as TCommand; if (c == null) throw new InvalidCastException($"Actual command type ({cmd.GetType()}) is not compatible with expected command type ({typeof(TCommand)})."); - AddParams(c); + if (t != null) c.Transaction = t; + AddParams(c); con.EnsureOpen(); return transform(c); } @@ -329,13 +339,14 @@ public T Execute(Func transform) /// /// The value from the return parameter. public object ExecuteReturn() - => UsingConnection(con => + => UsingConnection((con,t) => { using (var cmd = con.CreateCommand(Type, Command, Timeout)) { var c = cmd as TCommand; if (c == null) throw new InvalidCastException($"Actual command type ({cmd.GetType()}) is not compatible with expected command type ({typeof(TCommand)})."); - AddParams(c); + if (t != null) c.Transaction = t; + AddParams(c); var returnParameter = c.CreateParameter(); returnParameter.Direction = ParameterDirection.ReturnValue; c.Parameters.Add(returnParameter); diff --git a/ExpressiveDbCommand.cs b/ExpressiveDbCommand.cs index 2028531..a9d48bf 100644 --- a/ExpressiveDbCommand.cs +++ b/ExpressiveDbCommand.cs @@ -1,49 +1,40 @@ using System.Collections.Generic; using System.Data; using System.Data.Common; -using System.Linq; namespace Open.Database.Extensions { - /// - /// An abstraction for executing commands on a database using best practices and simplified expressive syntax. - /// - public class ExpressiveDbCommand : ExpressiveDbCommandBase + /// + /// An abstraction for executing commands on a database using best practices and simplified expressive syntax. + /// + public class ExpressiveDbCommand : ExpressiveDbCommandBase { /// The factory to generate connections from. /// The command type>. /// The SQL command. /// The list of params - public ExpressiveDbCommand(IDbConnectionFactory connFactory, CommandType type, string command, List @params) - : base(connFactory, type, command, @params?.ToList()) + public ExpressiveDbCommand( + IDbConnectionFactory connFactory, + CommandType type, + string command, + IEnumerable @params = null) + : base(connFactory, type, command, @params) { } - /// The factory to generate connections from. - /// The command type>. - /// The SQL command. - /// The list of params - public ExpressiveDbCommand(IDbConnectionFactory connFactory, CommandType type, string command, params Param[] @params) - : base(connFactory, type, command, @params?.ToList()) - { - } - - /// The connection to execute the command on. - /// The command type>. - /// The SQL command. - /// The list of params - public ExpressiveDbCommand(DbConnection connection, CommandType type, string command, List @params) - : base(connection, type, command, @params?.ToList()) - { - } - - /// The connection to execute the command on. - /// The command type>. - /// The SQL command. - /// The list of params - public ExpressiveDbCommand(DbConnection connection, CommandType type, string command, params Param[] @params) - : this(connection, type, command, @params?.ToList()) + /// The connection to execute the command on. + /// The optional transaction to execute the command on. + /// The command type>. + /// The SQL command. + /// The list of params + public ExpressiveDbCommand( + DbConnection connection, + DbTransaction transaction, + CommandType type, + string command, + IEnumerable @params = null) + : base(connection, transaction, type, command, @params) { } diff --git a/ExpressiveDbCommandBase.cs b/ExpressiveDbCommandBase.cs index 366ce8d..14a8d48 100644 --- a/ExpressiveDbCommandBase.cs +++ b/ExpressiveDbCommandBase.cs @@ -32,21 +32,23 @@ protected ExpressiveDbCommandBase( IDbConnectionFactory connFactory, CommandType type, string command, - List @params) + IEnumerable @params) : base(connFactory, type, command, @params) { } /// The connection to execute the command on. + /// The optional transaction to execute the command on. /// The command type>. /// The SQL command. /// The list of params protected ExpressiveDbCommandBase( TConnection connection, + IDbTransaction transaction, CommandType type, string command, - List @params) - : base(connection, type, command, @params) + IEnumerable @params) + : base(connection, transaction, type, command, @params) { } @@ -223,6 +225,7 @@ public Task IterateReaderAsync(Action handler, CancellationToken? t /// Iterates asynchronously until the handler returns false. Then cancels. /// /// If true, the iteration continues. + /// An optional cancellation token. /// The task that completes when the iteration is done or the predicate evaluates false. public Task IterateReaderAsyncWhile(Func predicate, CancellationToken? token = null) => ExecuteAsync(command => command.IterateReaderAsyncWhile(predicate), token); diff --git a/Extensions.ConnectionFactory.cs b/Extensions.ConnectionFactory.cs index 793dbf9..9dd9ac8 100644 --- a/Extensions.ConnectionFactory.cs +++ b/Extensions.ConnectionFactory.cs @@ -155,7 +155,20 @@ public static ExpressiveDbCommand Command( this DbConnection target, string command, CommandType type = CommandType.Text) - => new ExpressiveDbCommand(target, type, command); + => new ExpressiveDbCommand(target, null, type, command); + + /// + /// Creates an ExpressiveDbCommand for subsequent configuration and execution. + /// + /// The transaction to execute the command on. + /// The command text or stored procedure name to use. + /// The command type. + /// The resultant ExpressiveDbCommand. + public static ExpressiveDbCommand Command( + this DbTransaction target, + string command, + CommandType type = CommandType.Text) + => new ExpressiveDbCommand(target.Connection, target, type, command); /// /// Creates an ExpressiveDbCommand with command type set to StoredProcedure for subsequent configuration and execution. @@ -166,7 +179,18 @@ public static ExpressiveDbCommand Command( public static ExpressiveDbCommand StoredProcedure( this DbConnection target, string command) - => new ExpressiveDbCommand(target, CommandType.StoredProcedure, command); + => new ExpressiveDbCommand(target, null, CommandType.StoredProcedure, command); + + /// + /// Creates an ExpressiveDbCommand with command type set to StoredProcedure for subsequent configuration and execution. + /// + /// The transaction to execute the command on. + /// The command text or stored procedure name to use. + /// The resultant ExpressiveDbCommand. + public static ExpressiveDbCommand StoredProcedure( + this DbTransaction target, + string command) + => new ExpressiveDbCommand(target.Connection, target, CommandType.StoredProcedure, command); /// /// Creates an ExpressiveDbCommand for subsequent configuration and execution. diff --git a/Extensions.CreateCommand.cs b/Extensions.CreateCommand.cs new file mode 100644 index 0000000..3e7df15 --- /dev/null +++ b/Extensions.CreateCommand.cs @@ -0,0 +1,167 @@ +using System.Data; +using System.Data.Common; + +namespace Open.Database.Extensions +{ + public static partial class Extensions + { + /// + /// Shortcut for creating an IDbCommand from any IDbConnection. + /// + /// The connection to create a command from. + /// The command type. Text, StoredProcedure, or TableDirect. + /// The command text or stored procedure name to use. + /// The number of seconds to wait before the command times out. + /// The created SqlCommand. + public static IDbCommand CreateCommand(this IDbConnection connection, + CommandType type, string commandText, int secondsTimeout = CommandTimeout.DEFAULT_SECONDS) + { + var command = connection.CreateCommand(); + command.CommandType = type; + command.CommandText = commandText; + command.CommandTimeout = secondsTimeout; + + return command; + } + + /// + /// Shortcut for creating a text IDbCommand from any IDbConnection. + /// + /// The connection to create a command from. + /// The command text or stored procedure name to use. + /// The number of seconds to wait before the command times out. + /// The created SqlCommand. + public static IDbCommand CreateTextCommand(this IDbConnection connection, + string commandText, int secondsTimeout = CommandTimeout.DEFAULT_SECONDS) + => connection.CreateCommand(CommandType.Text, commandText, secondsTimeout); + + /// + /// Shortcut for creating an IDbCommand from any IDbConnection. + /// + /// The connection to create a command from. + /// The command text or stored procedure name to use. + /// The number of seconds to wait before the command times out. + /// The created SqlCommand. + public static IDbCommand CreateStoredProcedureCommand(this IDbConnection connection, + string commandText, int secondsTimeout = CommandTimeout.DEFAULT_SECONDS) + => connection.CreateCommand(CommandType.StoredProcedure, commandText, secondsTimeout); + + /// + /// Shortcut for creating an DbCommand from any DbConnection. + /// + /// The connection to create a command from. + /// The command type. Text, StoredProcedure, or TableDirect. + /// The command text or stored procedure name to use. + /// The number of seconds to wait before the command times out. + /// The created SqlCommand. + public static DbCommand CreateCommand(this DbConnection connection, + CommandType type, string commandText, int secondsTimeout = CommandTimeout.DEFAULT_SECONDS) + { + var command = connection.CreateCommand(); + command.CommandType = type; + command.CommandText = commandText; + command.CommandTimeout = secondsTimeout; + + return command; + } + + /// + /// Shortcut for creating a text DbCommand from any DbConnection. + /// + /// The connection to create a command from. + /// The command text or stored procedure name to use. + /// The number of seconds to wait before the command times out. + /// The created SqlCommand. + public static DbCommand CreateTextCommand(this DbConnection connection, + string commandText, int secondsTimeout = CommandTimeout.DEFAULT_SECONDS) + => connection.CreateCommand(CommandType.Text, commandText, secondsTimeout); + + /// + /// Shortcut for creating a stored procedure DbCommand from any DbConnection. + /// + /// The connection to create a command from. + /// The command text or stored procedure name to use. + /// The number of seconds to wait before the command times out. + /// The created SqlCommand. + public static DbCommand CreateStoredProcedureCommand(this DbConnection connection, + string procedureName, int secondsTimeout = CommandTimeout.DEFAULT_SECONDS) + => connection.CreateCommand(CommandType.StoredProcedure, procedureName, secondsTimeout); + + /// + /// Shortcut for creating an IDbCommand from any IDbTransaction. + /// + /// The transaction to create a command from. + /// The command type. Text, StoredProcedure, or TableDirect. + /// The command text or stored procedure name to use. + /// The number of seconds to wait before the command times out. + /// The created SqlCommand. + public static IDbCommand CreateCommand(this IDbTransaction transaction, + CommandType type, string commandText, int secondsTimeout = CommandTimeout.DEFAULT_SECONDS) + { + var command = transaction.Connection.CreateCommand(CommandType.StoredProcedure, commandText, secondsTimeout); + command.Transaction = transaction; + return command; + } + + /// + /// Shortcut for creating a text IDbCommand from any IDbTransaction. + /// + /// The transaction to create a command from. + /// The command text or stored procedure name to use. + /// The number of seconds to wait before the command times out. + /// The created SqlCommand. + public static IDbCommand CreateTextCommand(this IDbTransaction transaction, + string commandText, int secondsTimeout = CommandTimeout.DEFAULT_SECONDS) + => transaction.CreateCommand(CommandType.Text, commandText, secondsTimeout); + + /// + /// Shortcut for creating a stored procedure IDbCommand from any IDbTransaction. + /// + /// The transaction to create a command from. + /// The command text or stored procedure name to use. + /// The number of seconds to wait before the command times out. + /// The created SqlCommand. + public static IDbCommand CreateStoredProcedureCommand(this IDbTransaction transaction, + string procedureName, int secondsTimeout = CommandTimeout.DEFAULT_SECONDS) + => transaction.CreateCommand(CommandType.StoredProcedure, procedureName, secondsTimeout); + + /// + /// Shortcut for creating an DbCommand from any DbTransaction. + /// + /// The transaction to create a command from. + /// The command type. Text, StoredProcedure, or TableDirect. + /// The command text or stored procedure name to use. + /// The number of seconds to wait before the command times out. + /// The created SqlCommand. + public static DbCommand CreateCommand(this DbTransaction transaction, + CommandType type, string commandText, int secondsTimeout = CommandTimeout.DEFAULT_SECONDS) + { + var command = transaction.Connection.CreateCommand(CommandType.StoredProcedure, commandText, secondsTimeout); + command.Transaction = transaction; + return command; + } + + /// + /// Shortcut for creating a text DbCommand from any DbTransaction. + /// + /// The transaction to create a command from. + /// The command text or stored procedure name to use. + /// The number of seconds to wait before the command times out. + /// The created SqlCommand. + public static DbCommand CreateTextCommand(this DbTransaction transaction, + string commandText, int secondsTimeout = CommandTimeout.DEFAULT_SECONDS) + => transaction.CreateCommand(CommandType.Text, commandText, secondsTimeout); + + /// + /// Shortcut for creating a stored procedure DbCommand from any DbTransaction. + /// + /// The transaction to create a command from. + /// The command text or stored procedure name to use. + /// The number of seconds to wait before the command times out. + /// The created SqlCommand. + public static DbCommand CreateStoredProcedureCommand(this DbTransaction transaction, + string procedureName, int secondsTimeout = CommandTimeout.DEFAULT_SECONDS) + => transaction.CreateCommand(CommandType.StoredProcedure, procedureName, secondsTimeout); + + } +} diff --git a/Extensions.Transactions.cs b/Extensions.Transactions.cs index 44b990b..6b105ee 100644 --- a/Extensions.Transactions.cs +++ b/Extensions.Transactions.cs @@ -9,32 +9,35 @@ namespace Open.Database.Extensions public static partial class Extensions { + /// - /// Begins a transaction before executing the action. Commits if there are no exceptions and 'Commit' value from the action is true. Otherwise rolls-back the transaction. + /// Begins a transaction before executing the action. Commits if there are no exceptions, the 'Commit' value from the action is true and the optional cancellation token has not been cancelled. Otherwise rolls-back the transaction. /// - /// The connection type. /// The value returned from the action. /// The connection to transact with. - /// The handler to execute while a transaction is pending. Returning a 'Commit' value of true signals to commit the transaction. + /// The isolation level for the transaction. /// A optional token that if cancelled will cause this transaction to be aborted or rolled-back. + /// The handler to execute while a transaction is pending. Returning a 'Commit' value of true signals to commit the transaction. /// The value retured from the conditional action. - public static (bool Commit, T Value) ExecuteTransactionConditional( - this TConn connection, Func conditionalAction, CancellationToken? token = null) - where TConn : DbConnection + public static (bool Commit, T Value) ExecuteTransactionConditional( + this DbConnection connection, + IsolationLevel isolationLevel, + CancellationToken? token, + Func conditionalAction) { var t = token ?? CancellationToken.None; t.ThrowIfCancellationRequested(); var success = false; - IDbTransaction transaction = null; + DbTransaction transaction = null; connection.EnsureOpen(); t.ThrowIfCancellationRequested(); try { - transaction = connection.BeginTransaction(); - var result = conditionalAction(connection); + transaction = connection.BeginTransaction(isolationLevel); + var result = conditionalAction(transaction); t.ThrowIfCancellationRequested(); success = result.Commit; return result; @@ -50,63 +53,73 @@ public static (bool Commit, T Value) ExecuteTransactionConditional( } /// - /// Begins a transaction before executing the action. Commits if there are no exceptions and the conditional actio returns true. Otherwise rolls-back the transaction. + /// Begins a transaction before executing the action. Commits if there are no exceptions, the conditional action returns true, and the optional cancellation token is not cancelled. Otherwise rolls-back the transaction. /// - /// The connection type. /// The connection to transact with. - /// The handler to execute while a transaction is pending. Returning true signals to commit the transaction. + /// The isolation level for the transaction. /// A optional token that if cancelled will cause this transaction to be aborted or rolled-back. + /// The handler to execute while a transaction is pending. Returning true signals to commit the transaction. /// True if committed. - public static bool ExecuteTransactionConditional( - this TConn connection, Func conditionalAction, CancellationToken? token = null) - where TConn : DbConnection - => connection.ExecuteTransactionConditional(c => (conditionalAction(c), true), token).Commit; + public static bool ExecuteTransactionConditional( + this DbConnection connection, + IsolationLevel isolationLevel, + CancellationToken? token, + Func conditionalAction) + => connection.ExecuteTransactionConditional( + isolationLevel, token, t => (conditionalAction(t), true)).Commit; /// /// Begins a transaction before executing the action. Commits if there are no exceptions and the optional provided token is not cancelled. Otherwise rolls-back the transaction. /// - /// The connection type. /// The value returned from the action. /// The connection to transact with. - /// The handler to execute while a transaction is pending. + /// The isolation level for the transaction. /// A optional token that if cancelled will cause this transaction to be aborted or rolled-back. + /// The handler to execute while a transaction is pending. /// The value of the action. - public static T ExecuteTransaction( - this TConn connection, Func action, CancellationToken? token = null) - where TConn : DbConnection - => connection.ExecuteTransactionConditional(c => (true, action(c)), token).Value; + public static T ExecuteTransaction( + this DbConnection connection, + IsolationLevel isolationLevel, + CancellationToken? token, + Func action) + => connection.ExecuteTransactionConditional( + isolationLevel, token, t =>(true, action(t))).Value; /// /// Begins a transaction before executing the action. Commits if there are no exceptions and the optional provided token is not cancelled. Otherwise rolls-back the transaction. /// - /// The connection type. /// The connection to transact with. - /// The handler to execute while a transaction is pending. + /// The isolation level for the transaction. /// A optional token that if cancelled will cause this transaction to be aborted or rolled-back. - public static void ExecuteTransaction( - this TConn connection, Action action, CancellationToken? token = null) - where TConn : DbConnection - => connection.ExecuteTransaction(c => { action(c); return true; }, token); + /// The handler to execute while a transaction is pending. + public static void ExecuteTransaction( + this DbConnection connection, + IsolationLevel isolationLevel, + CancellationToken? token, + Action action) + => connection.ExecuteTransaction(isolationLevel, token, t => { action(t); return true; }); /// /// Begins a transaction before executing the action. Commits if there are no exceptions, the 'Commit' value from the action is true, and the optional provided token is not cancelled. Otherwise rolls-back the transaction. /// - /// The connection type. /// The value returned from the action. /// The connection to transact with. - /// The handler to execute while a transaction is pending. Returning a 'Commit' value of true signals to commit the transaction. + /// The isolation level for the transaction. /// A optional token that if cancelled will cause this transaction to be aborted or rolled-back. + /// The handler to execute while a transaction is pending. Returning a 'Commit' value of true signals to commit the transaction. /// The value of the awaited action. - public static async Task<(bool Commit, T Value)> ExecuteTransactionConditionalAsync( - this TConn connection, Func> conditionalAction, CancellationToken? token = null) - where TConn : DbConnection + public static async Task<(bool Commit, T Value)> ExecuteTransactionConditionalAsync( + this DbConnection connection, + IsolationLevel isolationLevel, + CancellationToken? token, + Func> conditionalAction) { var t = token ?? CancellationToken.None; t.ThrowIfCancellationRequested(); - + var success = false; - IDbTransaction transaction = null; + DbTransaction transaction = null; // Only await if needed... if (connection.State != ConnectionState.Open) @@ -117,8 +130,8 @@ public static void ExecuteTransaction( try { - transaction = connection.BeginTransaction(); - var result = await conditionalAction(connection); // If the task is cancelled, awaiting will throw. + transaction = connection.BeginTransaction(isolationLevel); + var result = await conditionalAction(transaction); // If the task is cancelled, awaiting will throw. t.ThrowIfCancellationRequested(); success = result.Commit; return result; @@ -136,42 +149,362 @@ public static void ExecuteTransaction( /// /// Begins a transaction before executing the action. Commits if there are no exceptions, the 'Commit' value from the action is true, and the optional provided token is not cancelled. Otherwise rolls-back the transaction. /// - /// The connection type. - /// The value returned from the action. /// The connection to transact with. + /// The isolation level for the transaction. + /// A optional token that if cancelled will cause this transaction to be aborted or rolled-back. /// The handler to execute while a transaction is pending. Returning true signals to commit the transaction. + /// The value of the awaited action. + public static async Task ExecuteTransactionConditionalAsync( + this DbConnection connection, + IsolationLevel isolationLevel, + CancellationToken? token, + Func> conditionalAction) + => (await connection.ExecuteTransactionConditionalAsync( + isolationLevel, token, async t => (await conditionalAction(t), true))).Commit; + + /// + /// Begins a transaction before executing the action. Commits if there are no exceptions and the optional provided token is not cancelled. Otherwise rolls-back the transaction. + /// + /// The value returned from the action. + /// The connection to transact with. + /// The isolation level for the transaction. /// A optional token that if cancelled will cause this transaction to be aborted or rolled-back. + /// The handler to execute while a transaction is pending. /// The value of the awaited action. - public static async Task ExecuteTransactionConditionalAsync( - this TConn connection, Func> conditionalAction, CancellationToken? token = null) - where TConn : DbConnection - => (await connection.ExecuteTransactionConditionalAsync(async c => (await conditionalAction(c), true), token)).Commit; + public static async Task ExecuteTransactionAsync( + this DbConnection connection, + IsolationLevel isolationLevel, + CancellationToken? token, + Func> action) + => (await connection.ExecuteTransactionConditionalAsync(isolationLevel, token, async t => (true, await action(t)))).Value; /// /// Begins a transaction before executing the action. Commits if there are no exceptions and the optional provided token is not cancelled. Otherwise rolls-back the transaction. /// - /// The connection type. + /// The connection to transact with. + /// The isolation level for the transaction. + /// A optional token that if cancelled will cause this transaction to be aborted or rolled-back. + /// The handler to execute while a transaction is pending. + public static Task ExecuteTransactionAsync( + this DbConnection connection, + IsolationLevel isolationLevel, + CancellationToken? token, + Func action) + => connection.ExecuteTransactionAsync(isolationLevel, token, async c => { await action(c); return true; }); + + #region Overloads + + #region No Token + /// + /// Begins a transaction before executing the action. Commits if there are no exceptions and 'Commit' value from the action is true. Otherwise rolls-back the transaction. + /// + /// The value returned from the action. + /// The connection to transact with. + /// The isolation level for the transaction. + /// The handler to execute while a transaction is pending. Returning a 'Commit' value of true signals to commit the transaction. + /// The value retured from the conditional action. + public static (bool Commit, T Value) ExecuteTransactionConditional( + this DbConnection connection, + IsolationLevel isolationLevel, + Func conditionalAction) + => connection.ExecuteTransactionConditional(isolationLevel, null, conditionalAction); + + /// + /// Begins a transaction before executing the action. Commits if there are no exceptions and the conditional action returns true. Otherwise rolls-back the transaction. + /// + /// The connection to transact with. + /// The isolation level for the transaction. + /// The handler to execute while a transaction is pending. Returning true signals to commit the transaction. + /// True if committed. + public static bool ExecuteTransactionConditional( + this DbConnection connection, + IsolationLevel isolationLevel, + Func conditionalAction) + => connection.ExecuteTransactionConditional(isolationLevel, null, conditionalAction); + + /// + /// Begins a transaction before executing the action. Commits if there are no exceptions. Otherwise rolls-back the transaction. + /// + /// The value returned from the action. + /// The connection to transact with. + /// The isolation level for the transaction. + /// The handler to execute while a transaction is pending. + /// The value of the action. + public static T ExecuteTransaction( + this DbConnection connection, + IsolationLevel isolationLevel, + Func action) + => connection.ExecuteTransaction(isolationLevel, null, action); + + /// + /// Begins a transaction before executing the action. Commits if there are no exceptions. Otherwise rolls-back the transaction. + /// + /// The connection to transact with. + /// The isolation level for the transaction. + /// The handler to execute while a transaction is pending. + public static void ExecuteTransaction( + this DbConnection connection, + IsolationLevel isolationLevel, + Action action) + => connection.ExecuteTransaction(isolationLevel, null, action); + + /// + /// Begins a transaction before executing the action. Commits if there are no exceptions and the 'Commit' value from the action is true. Otherwise rolls-back the transaction. + /// + /// The value returned from the action. + /// The connection to transact with. + /// The isolation level for the transaction. + /// The handler to execute while a transaction is pending. Returning a 'Commit' value of true signals to commit the transaction. + /// The value of the awaited action. + public static Task<(bool Commit, T Value)> ExecuteTransactionConditionalAsync( + this DbConnection connection, + IsolationLevel isolationLevel, + Func> conditionalAction) + => connection.ExecuteTransactionConditionalAsync(isolationLevel, null, conditionalAction); + + /// + /// Begins a transaction before executing the action. Commits if there are no exceptions and the value from the action is true. Otherwise rolls-back the transaction. + /// + /// The connection to transact with. + /// The isolation level for the transaction. + /// The handler to execute while a transaction is pending. Returning true signals to commit the transaction. + /// The value of the awaited action. + public static Task ExecuteTransactionConditionalAsync( + this DbConnection connection, + IsolationLevel isolationLevel, + Func> conditionalAction) + => connection.ExecuteTransactionConditionalAsync(isolationLevel, null, conditionalAction); + + /// + /// Begins a transaction before executing the action. Commits if there are no exceptions. Otherwise rolls-back the transaction. + /// /// The value returned from the action. /// The connection to transact with. + /// The isolation level for the transaction. /// The handler to execute while a transaction is pending. + /// The value of the awaited action. + public static Task ExecuteTransactionAsync( + this DbConnection connection, + IsolationLevel isolationLevel, + Func> action) + => connection.ExecuteTransactionAsync(isolationLevel, null, action); + + /// + /// Begins a transaction before executing the action. Commits if there are no exceptions. Otherwise rolls-back the transaction. + /// + /// The connection to transact with. + /// The isolation level for the transaction. + /// The handler to execute while a transaction is pending. + public static Task ExecuteTransactionAsync( + this DbConnection connection, + IsolationLevel isolationLevel, + Func action) + => connection.ExecuteTransactionAsync(isolationLevel, null, action); + + #endregion + + #region Unspecified Isolation Level + /// + /// Begins a transaction before executing the action. Commits if there are no exceptions, the 'Commit' value from the action is true and the optional cancellation token has not been cancelled. Otherwise rolls-back the transaction. + /// + /// The value returned from the action. + /// The connection to transact with. /// A optional token that if cancelled will cause this transaction to be aborted or rolled-back. + /// The handler to execute while a transaction is pending. Returning a 'Commit' value of true signals to commit the transaction. + /// The value retured from the conditional action. + public static (bool Commit, T Value) ExecuteTransactionConditional( + this DbConnection connection, + CancellationToken? token, + Func conditionalAction) + => connection.ExecuteTransactionConditional(IsolationLevel.Unspecified, token, conditionalAction); + + /// + /// Begins a transaction before executing the action. Commits if there are no exceptions, the conditional action returns true, and the optional cancellation token is not cancelled. Otherwise rolls-back the transaction. + /// + /// The connection to transact with. + /// A optional token that if cancelled will cause this transaction to be aborted or rolled-back. + /// The handler to execute while a transaction is pending. Returning true signals to commit the transaction. + /// True if committed. + public static bool ExecuteTransactionConditional( + this DbConnection connection, + CancellationToken? token, + Func conditionalAction) + => connection.ExecuteTransactionConditional(IsolationLevel.Unspecified, token, conditionalAction); + + /// + /// Begins a transaction before executing the action. Commits if there are no exceptions and the optional provided token is not cancelled. Otherwise rolls-back the transaction. + /// + /// The value returned from the action. + /// The connection to transact with. + /// A optional token that if cancelled will cause this transaction to be aborted or rolled-back. + /// The handler to execute while a transaction is pending. + /// The value of the action. + public static T ExecuteTransaction( + this DbConnection connection, + CancellationToken? token, + Func action) + => connection.ExecuteTransaction(IsolationLevel.Unspecified, token, action); + + /// + /// Begins a transaction before executing the action. Commits if there are no exceptions and the optional provided token is not cancelled. Otherwise rolls-back the transaction. + /// + /// The connection to transact with. + /// A optional token that if cancelled will cause this transaction to be aborted or rolled-back. + /// The handler to execute while a transaction is pending. + public static void ExecuteTransaction( + this DbConnection connection, + CancellationToken? token, + Action action) + => connection.ExecuteTransaction(IsolationLevel.Unspecified, token, action); + + /// + /// Begins a transaction before executing the action. Commits if there are no exceptions, the 'Commit' value from the action is true, and the optional provided token is not cancelled. Otherwise rolls-back the transaction. + /// + /// The value returned from the action. + /// The connection to transact with. + /// A optional token that if cancelled will cause this transaction to be aborted or rolled-back. + /// The handler to execute while a transaction is pending. Returning a 'Commit' value of true signals to commit the transaction. + /// The value of the awaited action. + public static Task<(bool Commit, T Value)> ExecuteTransactionConditionalAsync( + this DbConnection connection, + CancellationToken? token, + Func> conditionalAction) + => connection.ExecuteTransactionConditionalAsync(IsolationLevel.Unspecified, token, conditionalAction); + + /// + /// Begins a transaction before executing the action. Commits if there are no exceptions, the value from the action is true, and the optional provided token is not cancelled. Otherwise rolls-back the transaction. + /// + /// The connection to transact with. + /// A optional token that if cancelled will cause this transaction to be aborted or rolled-back. + /// The handler to execute while a transaction is pending. Returning true signals to commit the transaction. /// The value of the awaited action. - public static async Task ExecuteTransactionAsync( - this TConn connection, Func> action, CancellationToken? token = null) - where TConn : DbConnection - => (await connection.ExecuteTransactionConditionalAsync(async c => (true, await action(c)), token)).Value; + public static Task ExecuteTransactionConditionalAsync( + this DbConnection connection, + CancellationToken? token, + Func> conditionalAction) + => connection.ExecuteTransactionConditionalAsync(IsolationLevel.Unspecified, token, conditionalAction); /// /// Begins a transaction before executing the action. Commits if there are no exceptions and the optional provided token is not cancelled. Otherwise rolls-back the transaction. /// - /// The connection type. + /// The value returned from the action. /// The connection to transact with. + /// A optional token that if cancelled will cause this transaction to be aborted or rolled-back. /// The handler to execute while a transaction is pending. + /// The value of the awaited action. + public static Task ExecuteTransactionAsync( + this DbConnection connection, + CancellationToken? token, + Func> action) + => connection.ExecuteTransactionAsync(IsolationLevel.Unspecified, token, action); + + /// + /// Begins a transaction before executing the action. Commits if there are no exceptions and the optional provided token is not cancelled. Otherwise rolls-back the transaction. + /// + /// The connection to transact with. /// A optional token that if cancelled will cause this transaction to be aborted or rolled-back. - public static Task ExecuteTransactionAsync( - this TConn connection, Func action, CancellationToken? token = null) - where TConn : DbConnection - => connection.ExecuteTransactionAsync(async c => { await action(c); return true; }, token); + /// The handler to execute while a transaction is pending. + public static Task ExecuteTransactionAsync( + this DbConnection connection, + CancellationToken? token, + Func action) + => connection.ExecuteTransactionAsync(IsolationLevel.Unspecified, token, action); + + #endregion + + #region Defaults Only + /// + /// Begins a transaction before executing the action. Commits if there are no exceptions and 'Commit' value from the action is true. Otherwise rolls-back the transaction. + /// + /// The value returned from the action. + /// The connection to transact with. + /// The handler to execute while a transaction is pending. Returning a 'Commit' value of true signals to commit the transaction. + /// The value retured from the conditional action. + public static (bool Commit, T Value) ExecuteTransactionConditional( + this DbConnection connection, + Func conditionalAction) + => connection.ExecuteTransactionConditional(IsolationLevel.Unspecified, null, conditionalAction); + + /// + /// Begins a transaction before executing the action. Commits if there are no exceptions and the conditional action returns true. Otherwise rolls-back the transaction. + /// + /// The connection to transact with. + /// The handler to execute while a transaction is pending. Returning true signals to commit the transaction. + /// True if committed. + public static bool ExecuteTransactionConditional( + this DbConnection connection, + Func conditionalAction) + => connection.ExecuteTransactionConditional(IsolationLevel.Unspecified, null, conditionalAction); + + /// + /// Begins a transaction before executing the action. Commits if there are no exceptions. Otherwise rolls-back the transaction. + /// + /// The value returned from the action. + /// The connection to transact with. + /// The handler to execute while a transaction is pending. + /// The value of the action. + public static T ExecuteTransaction( + this DbConnection connection, + Func action) + => connection.ExecuteTransaction(IsolationLevel.Unspecified, null, action); + + /// + /// Begins a transaction before executing the action. Commits if there are no exceptions. Otherwise rolls-back the transaction. + /// + /// The connection to transact with. + /// The handler to execute while a transaction is pending. + public static void ExecuteTransaction( + this DbConnection connection, + Action action) + => connection.ExecuteTransaction(IsolationLevel.Unspecified, null, action); + + /// + /// Begins a transaction before executing the action. Commits if there are no exceptions and the 'Commit' value from the action is true. Otherwise rolls-back the transaction. + /// + /// The value returned from the action. + /// The connection to transact with. + /// The handler to execute while a transaction is pending. Returning a 'Commit' value of true signals to commit the transaction. + /// The value of the awaited action. + public static Task<(bool Commit, T Value)> ExecuteTransactionConditionalAsync( + this DbConnection connection, + Func> conditionalAction) + => connection.ExecuteTransactionConditionalAsync(IsolationLevel.Unspecified, null, conditionalAction); + + /// + /// Begins a transaction before executing the action. Commits if there are no exceptions and the value from the action is true. Otherwise rolls-back the transaction. + /// + /// The connection to transact with. + /// The handler to execute while a transaction is pending. Returning true signals to commit the transaction. + /// The value of the awaited action. + public static Task ExecuteTransactionConditionalAsync( + this DbConnection connection, + Func> conditionalAction) + => connection.ExecuteTransactionConditionalAsync(IsolationLevel.Unspecified, null, conditionalAction); + + /// + /// Begins a transaction before executing the action. Commits if there are no exceptions. Otherwise rolls-back the transaction. + /// + /// The value returned from the action. + /// The connection to transact with. + /// The handler to execute while a transaction is pending. + /// The value of the awaited action. + public static Task ExecuteTransactionAsync( + this DbConnection connection, + Func> action) + => connection.ExecuteTransactionAsync(IsolationLevel.Unspecified, null, action); + + /// + /// Begins a transaction before executing the action. Commits if there are no exceptions. Otherwise rolls-back the transaction. + /// + /// The connection to transact with. + /// The handler to execute while a transaction is pending. + public static Task ExecuteTransactionAsync( + this DbConnection connection, + Func action) + => connection.ExecuteTransactionAsync(IsolationLevel.Unspecified, null, action); + + #endregion + #endregion } } diff --git a/Extensions.cs b/Extensions.cs index 498a47e..f2a5521 100644 --- a/Extensions.cs +++ b/Extensions.cs @@ -120,65 +120,6 @@ public static async Task EnsureOpenAsync(this DbConnection conn return state; } - /// - /// Shortcut for creating an IDbCommand from any IDbConnection. - /// - /// The connection to create a command from. - /// The command type. Text, StoredProcedure, or TableDirect. - /// The command text or stored procedure name to use. - /// The number of seconds to wait before the command times out. - /// The created SqlCommand. - public static IDbCommand CreateCommand(this IDbConnection connection, - CommandType type, string commandText, int secondsTimeout = CommandTimeout.DEFAULT_SECONDS) - { - var command = connection.CreateCommand(); - command.CommandType = type; - command.CommandText = commandText; - command.CommandTimeout = secondsTimeout; - - return command; - } - - /// - /// Shortcut for creating an IDbCommand from any IDbConnection. - /// - /// The connection to create a command from. - /// The command text or stored procedure name to use. - /// The number of seconds to wait before the command times out. - /// The created SqlCommand. - public static IDbCommand CreateStoredProcedureCommand(this IDbConnection connection, - string commandText, int secondsTimeout = CommandTimeout.DEFAULT_SECONDS) - => connection.CreateCommand(CommandType.StoredProcedure, commandText, secondsTimeout); - - /// - /// Shortcut for creating an DbCommand from any DbConnection. - /// - /// The connection to create a command from. - /// The command type. Text, StoredProcedure, or TableDirect. - /// The command text or stored procedure name to use. - /// The number of seconds to wait before the command times out. - /// The created SqlCommand. - public static DbCommand CreateCommand(this DbConnection connection, - CommandType type, string commandText, int secondsTimeout = CommandTimeout.DEFAULT_SECONDS) - { - var command = connection.CreateCommand(); - command.CommandType = type; - command.CommandText = commandText; - command.CommandTimeout = secondsTimeout; - - return command; - } - - /// - /// Shortcut for creating an DbCommand from any DbConnection. - /// - /// The connection to create a command from. - /// The command text or stored procedure name to use. - /// The number of seconds to wait before the command times out. - /// The created SqlCommand. - public static DbCommand CreateStoredProcedureCommand(this DbConnection connection, - string commandText, int secondsTimeout = CommandTimeout.DEFAULT_SECONDS) - => connection.CreateCommand(CommandType.StoredProcedure, commandText, secondsTimeout); /// /// Shortcut for adding command parameter. @@ -198,6 +139,8 @@ public static IDbDataParameter AddParameter(this IDbCommand target, return c; } + + /// /// Shortcut for adding command parameter. /// diff --git a/Open.Database.Extensions.csproj b/Open.Database.Extensions.csproj index ba9b67a..0c7136b 100644 --- a/Open.Database.Extensions.csproj +++ b/Open.Database.Extensions.csproj @@ -11,12 +11,13 @@ Useful set of utilities and abstractions for simplifying modern data-access operations and ensuring DI compatibility. https://github.com/electricessence/Open.Database.Extensions git - 5.8.0 - 5.8.0.0 - 5.8.0.0 - Improved connection state/open intellegence for all connection and command extensions. -Added missing async extensions for commands. (Was assumed to use expressive commands only.) -Added more useful connection factory extensions. + 5.9.0 + 5.9.0.0 + 5.9.0.0 + Implemented correct transaction flow. +Added extensions for creating commands from transactions. +Expanded expressive commands to allow for transactions. +Added examples. @@ -30,10 +31,13 @@ Added more useful connection factory extensions. + + + diff --git a/README.md b/README.md index b3aaaf0..0e9028f 100644 --- a/README.md +++ b/README.md @@ -110,15 +110,22 @@ Example: ```cs // Returns true if the transaction is successful. - public static bool DoTransaction() + public static bool TryTransaction() => ConnectionFactory.Using(connection => // Open a connection and start a transaction. - connection.ExecuteTransactionConditional(c => { - /* - * Do some complex data access requring a potential roll-back. - */ - - // Commit transation if true. Roll-back if false. - return true; + connection.ExecuteTransactionConditional(transaction => { + + // First procedure does some updates. + var count = transaction + .StoredProcedure("[Updated Procedure]") + .ExecuteNonQuery(); + + // Second procedure validates the results. + // If it returns true, then the transaction is commited. + // If it returns false, then the transaction is rolled back. + return transaction + .StoredProcedure("[Validation Procedure]") + .AddParam("@ExpectedCount", count) + .ExecuteScalar(); })); ``` diff --git a/SqlClient/ExpressiveSqlCommand.cs b/SqlClient/ExpressiveSqlCommand.cs index 8514561..cd973fa 100644 --- a/SqlClient/ExpressiveSqlCommand.cs +++ b/SqlClient/ExpressiveSqlCommand.cs @@ -15,38 +15,30 @@ public class ExpressiveSqlCommand : ExpressiveDbCommandBaseThe command type>. /// The SQL command. /// The list of params - public ExpressiveSqlCommand(IDbConnectionFactory connFactory, CommandType type, string command, List @params = null) + public ExpressiveSqlCommand( + IDbConnectionFactory connFactory, + CommandType type, + string command, + IEnumerable @params = null) : base(connFactory, type, command, @params) { } - /// The factory to generate connections from. - /// The command type>. - /// The SQL command. - /// The list of params - public ExpressiveSqlCommand(IDbConnectionFactory connFactory, CommandType type, string command, params Param[] @params) - : base(connFactory, type, command, @params.ToList()) - { - } - - - /// The connection to execute the command on. - /// The command type>. - /// The SQL command. - /// The list of params - public ExpressiveSqlCommand(SqlConnection connection, CommandType type, string command, List @params) - : base(connection, type, command, @params?.ToList()) + /// The connection to execute the command on. + /// The optional transaction to execute the command on. + /// The command type>. + /// The SQL command. + /// The list of params + public ExpressiveSqlCommand( + SqlConnection connection, + SqlTransaction transaction, + CommandType type, + string command, + IEnumerable @params = null) + : base(connection, transaction, type, command, @params) { } - /// The connection to execute the command on. - /// The command type>. - /// The SQL command. - /// The list of params - public ExpressiveSqlCommand(SqlConnection connection, CommandType type, string command, params Param[] @params) - : base(connection, type, command, @params?.ToList()) - { - } /// /// Handles adding the list of parameters to a new command. diff --git a/SqlClient/Extensions.CreateCommand.cs b/SqlClient/Extensions.CreateCommand.cs new file mode 100644 index 0000000..8fb60da --- /dev/null +++ b/SqlClient/Extensions.CreateCommand.cs @@ -0,0 +1,90 @@ +using System.Data; +using System.Data.Common; +using System.Data.SqlClient; + +namespace Open.Database.Extensions.SqlClient +{ + public static partial class Extensions + { + + /// + /// Shortcut for creating an SqlCommand from any SqlConnection. + /// + /// The connection to create a command from. + /// The command type. Text, StoredProcedure, or TableDirect. + /// The command text or stored procedure name to use. + /// The number of seconds to wait before the command times out. + /// The created SqlCommand. + public static SqlCommand CreateCommand(this SqlConnection connection, + CommandType type, string commandText, int secondsTimeout = CommandTimeout.DEFAULT_SECONDS) + { + var command = connection.CreateCommand(); + command.CommandType = type; + command.CommandText = commandText; + command.CommandTimeout = secondsTimeout; + + return command; + } + + /// + /// Shortcut for creating an text SqlCommand from any SqlConnection. + /// + /// The connection to create a command from. + /// The command text or stored procedure name to use. + /// The number of seconds to wait before the command times out. + /// The created SqlCommand. + public static SqlCommand CreateTextCommand(this SqlConnection connection, + string commandText, int secondsTimeout = CommandTimeout.DEFAULT_SECONDS) + => connection.CreateCommand(CommandType.Text, commandText, secondsTimeout); + + /// + /// Shortcut for creating a stored procedure SqlCommand from any SqlConnection. + /// + /// The connection to create a command from. + /// The command text or stored procedure name to use. + /// The number of seconds to wait before the command times out. + /// The created SqlCommand. + public static SqlCommand CreateStoredProcedureCommand(this SqlConnection connection, + string procedureName, int secondsTimeout = CommandTimeout.DEFAULT_SECONDS) + => connection.CreateCommand(CommandType.StoredProcedure, procedureName, secondsTimeout); + + /// + /// Shortcut for creating an SqlCommand from any SqlTransaction. + /// + /// The transaction to create a command from. + /// The command type. Text, StoredProcedure, or TableDirect. + /// The command text or stored procedure name to use. + /// The number of seconds to wait before the command times out. + /// The created SqlCommand. + public static SqlCommand CreateCommand(this SqlTransaction transaction, + CommandType type, string commandText, int secondsTimeout = CommandTimeout.DEFAULT_SECONDS) + { + var command = transaction.Connection.CreateCommand(CommandType.StoredProcedure, commandText, secondsTimeout); + command.Transaction = transaction; + return command; + } + + /// + /// Shortcut for creating a text SqlCommand from any SqlTransaction. + /// + /// The transaction to create a command from. + /// The command text or stored procedure name to use. + /// The number of seconds to wait before the command times out. + /// The created SqlCommand. + public static SqlCommand CreateTextCommand(this SqlTransaction transaction, + string procedureName, int secondsTimeout = CommandTimeout.DEFAULT_SECONDS) + => transaction.CreateCommand(CommandType.Text, procedureName, secondsTimeout); + + /// + /// Shortcut for creating a stored procedure SqlCommand from any SqlTransaction. + /// + /// The transaction to create a command from. + /// The command text or stored procedure name to use. + /// The number of seconds to wait before the command times out. + /// The created SqlCommand. + public static SqlCommand CreateStoredProcedureCommand(this SqlTransaction transaction, + string procedureName, int secondsTimeout = CommandTimeout.DEFAULT_SECONDS) + => transaction.CreateCommand(CommandType.StoredProcedure, procedureName, secondsTimeout); + + } +} diff --git a/SqlClient/Extensions.Expressive.cs b/SqlClient/Extensions.Expressive.cs new file mode 100644 index 0000000..4e7e6fc --- /dev/null +++ b/SqlClient/Extensions.Expressive.cs @@ -0,0 +1,102 @@ +using System; +using System.Data; +using System.Data.SqlClient; + +namespace Open.Database.Extensions.SqlClient +{ + public static partial class Extensions + { + /// + /// Creates an ExpressiveSqlCommand for subsequent configuration and execution. + /// + /// The connection to execute the command on. + /// The command text or stored procedure name to use. + /// The command type. + /// The resultant ExpressiveSqlCommand. + public static ExpressiveSqlCommand Command( + this SqlConnection target, + string command, CommandType type = CommandType.Text) + => new ExpressiveSqlCommand(target, null, type, command); + + /// + /// Creates an ExpressiveSqlCommand for subsequent configuration and execution. + /// + /// The transaction to execute the command on. + /// The command text or stored procedure name to use. + /// The command type. + /// The resultant ExpressiveSqlCommand. + public static ExpressiveSqlCommand Command( + this SqlTransaction target, + string command, CommandType type = CommandType.Text) + => new ExpressiveSqlCommand(target.Connection, target, type, command); + + /// + /// Creates an ExpressiveSqlCommand with command type set to StoredProcedure for subsequent configuration and execution. + /// + /// The connection to execute the command on. + /// The command text or stored procedure name to use. + /// The resultant ExpressiveSqlCommand. + public static ExpressiveSqlCommand StoredProcedure( + this SqlConnection target, + string command) + => new ExpressiveSqlCommand(target, null, CommandType.StoredProcedure, command); + + /// + /// Creates an ExpressiveSqlCommand with command type set to StoredProcedure for subsequent configuration and execution. + /// + /// The transaction to execute the command on. + /// The command text or stored procedure name to use. + /// The resultant ExpressiveSqlCommand. + public static ExpressiveSqlCommand StoredProcedure( + this SqlTransaction target, + string command) + => new ExpressiveSqlCommand(target.Connection, target, CommandType.StoredProcedure, command); + + /// + /// Creates an ExpressiveSqlCommand for subsequent configuration and execution. + /// + /// The connection factory to generate a commands from. + /// The command text or stored procedure name to use. + /// The command type. + /// The resultant ExpressiveSqlCommand. + public static ExpressiveSqlCommand Command( + this IDbConnectionFactory target, + string command, CommandType type = CommandType.Text) + => new ExpressiveSqlCommand(target, type, command); + + /// + /// Creates an ExpressiveSqlCommand with command type set to StoredProcedure for subsequent configuration and execution. + /// + /// The connection factory to generate a commands from. + /// The command text or stored procedure name to use. + /// The resultant ExpressiveSqlCommand. + public static ExpressiveSqlCommand StoredProcedure( + this IDbConnectionFactory target, + string command) + => new ExpressiveSqlCommand(target, CommandType.StoredProcedure, command); + + /// + /// Creates an ExpressiveSqlCommand for subsequent configuration and execution. + /// + /// The connection factory to generate a commands from. + /// The command text or stored procedure name to use. + /// The command type. + /// The resultant ExpressiveSqlCommand. + public static ExpressiveSqlCommand Command( + this Func target, + string command, CommandType type = CommandType.Text) + => Command(new DbConnectionFactory(target), command, type); + + /// + /// Creates an ExpressiveSqlCommand with command type set to StoredProcedure for subsequent configuration and execution. + /// + /// The connection factory to generate a commands from. + /// The command text or stored procedure name to use. + /// The resultant ExpressiveSqlCommand. + public static ExpressiveSqlCommand StoredProcedure( + this Func target, + string command) + => StoredProcedure(new DbConnectionFactory(target), command); + + } +} diff --git a/SqlClient/Extensions.Transactions.cs b/SqlClient/Extensions.Transactions.cs new file mode 100644 index 0000000..73d4b74 --- /dev/null +++ b/SqlClient/Extensions.Transactions.cs @@ -0,0 +1,515 @@ +using System; +using System.Collections.Generic; +using System.Text; +using System.Data.SqlClient; +using System.Data; +using System.Threading; +using System.Threading.Tasks; + +namespace Open.Database.Extensions.SqlClient +{ + // NOTE: This is simply a copy/paste of th IDb and Db extensions but replacing types with their Sql versions. + // Why? To ensure the Sql types are propagated through the type flow. + + public static partial class Extensions + { + + /// + /// Begins a transaction before executing the action. Commits if there are no exceptions, the 'Commit' value from the action is true and the optional cancellation token has not been cancelled. Otherwise rolls-back the transaction. + /// + /// The value returned from the action. + /// The connection to transact with. + /// The isolation level for the transaction. + /// A optional token that if cancelled will cause this transaction to be aborted or rolled-back. + /// The handler to execute while a transaction is pending. Returning a 'Commit' value of true signals to commit the transaction. + /// The value retured from the conditional action. + public static (bool Commit, T Value) ExecuteTransactionConditional( + this SqlConnection connection, + IsolationLevel isolationLevel, + CancellationToken? token, + Func conditionalAction) + { + var t = token ?? CancellationToken.None; + t.ThrowIfCancellationRequested(); + + var success = false; + SqlTransaction transaction = null; + + connection.EnsureOpen(); + t.ThrowIfCancellationRequested(); + + try + { + transaction = connection.BeginTransaction(isolationLevel); + var result = conditionalAction(transaction); + t.ThrowIfCancellationRequested(); + success = result.Commit; + return result; + } + finally + { + if (transaction != null) // Just in case acquiring a transaction fails. + { + if (success) transaction.Commit(); + else transaction.Rollback(); + } + } + } + + /// + /// Begins a transaction before executing the action. Commits if there are no exceptions, the conditional action returns true, and the optional cancellation token is not cancelled. Otherwise rolls-back the transaction. + /// + /// The connection to transact with. + /// The isolation level for the transaction. + /// A optional token that if cancelled will cause this transaction to be aborted or rolled-back. + /// The handler to execute while a transaction is pending. Returning true signals to commit the transaction. + /// True if committed. + public static bool ExecuteTransactionConditional( + this SqlConnection connection, + IsolationLevel isolationLevel, + CancellationToken? token, + Func conditionalAction) + => connection.ExecuteTransactionConditional( + isolationLevel, token, t => (conditionalAction(t), true)).Commit; + + /// + /// Begins a transaction before executing the action. Commits if there are no exceptions and the optional provided token is not cancelled. Otherwise rolls-back the transaction. + /// + /// The value returned from the action. + /// The connection to transact with. + /// The isolation level for the transaction. + /// A optional token that if cancelled will cause this transaction to be aborted or rolled-back. + /// The handler to execute while a transaction is pending. + /// The value of the action. + public static T ExecuteTransaction( + this SqlConnection connection, + IsolationLevel isolationLevel, + CancellationToken? token, + Func action) + => connection.ExecuteTransactionConditional( + isolationLevel, token, t => (true, action(t))).Value; + + /// + /// Begins a transaction before executing the action. Commits if there are no exceptions and the optional provided token is not cancelled. Otherwise rolls-back the transaction. + /// + /// The connection to transact with. + /// The isolation level for the transaction. + /// A optional token that if cancelled will cause this transaction to be aborted or rolled-back. + /// The handler to execute while a transaction is pending. + public static void ExecuteTransaction( + this SqlConnection connection, + IsolationLevel isolationLevel, + CancellationToken? token, + Action action) + => connection.ExecuteTransaction(isolationLevel, token, t => { action(t); return true; }); + + + /// + /// Begins a transaction before executing the action. Commits if there are no exceptions, the 'Commit' value from the action is true, and the optional provided token is not cancelled. Otherwise rolls-back the transaction. + /// + /// The value returned from the action. + /// The connection to transact with. + /// The isolation level for the transaction. + /// A optional token that if cancelled will cause this transaction to be aborted or rolled-back. + /// The handler to execute while a transaction is pending. Returning a 'Commit' value of true signals to commit the transaction. + /// The value of the awaited action. + public static async Task<(bool Commit, T Value)> ExecuteTransactionConditionalAsync( + this SqlConnection connection, + IsolationLevel isolationLevel, + CancellationToken? token, + Func> conditionalAction) + { + var t = token ?? CancellationToken.None; + t.ThrowIfCancellationRequested(); + + var success = false; + SqlTransaction transaction = null; + + // Only await if needed... + if (connection.State != ConnectionState.Open) + { + await connection.EnsureOpenAsync(t); // If the task is cancelled, awaiting will throw. + t.ThrowIfCancellationRequested(); + } + + try + { + transaction = connection.BeginTransaction(isolationLevel); + var result = await conditionalAction(transaction); // If the task is cancelled, awaiting will throw. + t.ThrowIfCancellationRequested(); + success = result.Commit; + return result; + } + finally + { + if (transaction != null) // Just in case acquiring a transaction fails. + { + if (success) transaction.Commit(); + else transaction.Rollback(); + } + } + } + + /// + /// Begins a transaction before executing the action. Commits if there are no exceptions, the 'Commit' value from the action is true, and the optional provided token is not cancelled. Otherwise rolls-back the transaction. + /// + /// The connection to transact with. + /// The isolation level for the transaction. + /// A optional token that if cancelled will cause this transaction to be aborted or rolled-back. + /// The handler to execute while a transaction is pending. Returning true signals to commit the transaction. + /// The value of the awaited action. + public static async Task ExecuteTransactionConditionalAsync( + this SqlConnection connection, + IsolationLevel isolationLevel, + CancellationToken? token, + Func> conditionalAction) + => (await connection.ExecuteTransactionConditionalAsync( + isolationLevel, token, async t => (await conditionalAction(t), true))).Commit; + + /// + /// Begins a transaction before executing the action. Commits if there are no exceptions and the optional provided token is not cancelled. Otherwise rolls-back the transaction. + /// + /// The value returned from the action. + /// The connection to transact with. + /// The isolation level for the transaction. + /// A optional token that if cancelled will cause this transaction to be aborted or rolled-back. + /// The handler to execute while a transaction is pending. + /// The value of the awaited action. + public static async Task ExecuteTransactionAsync( + this SqlConnection connection, + IsolationLevel isolationLevel, + CancellationToken? token, + Func> action) + => (await connection.ExecuteTransactionConditionalAsync(isolationLevel, token, async t => (true, await action(t)))).Value; + + /// + /// Begins a transaction before executing the action. Commits if there are no exceptions and the optional provided token is not cancelled. Otherwise rolls-back the transaction. + /// + /// The connection to transact with. + /// The isolation level for the transaction. + /// A optional token that if cancelled will cause this transaction to be aborted or rolled-back. + /// The handler to execute while a transaction is pending. + public static Task ExecuteTransactionAsync( + this SqlConnection connection, + IsolationLevel isolationLevel, + CancellationToken? token, + Func action) + => connection.ExecuteTransactionAsync(isolationLevel, token, async c => { await action(c); return true; }); + + #region Overloads + + #region No Token + /// + /// Begins a transaction before executing the action. Commits if there are no exceptions and 'Commit' value from the action is true. Otherwise rolls-back the transaction. + /// + /// The value returned from the action. + /// The connection to transact with. + /// The isolation level for the transaction. + /// The handler to execute while a transaction is pending. Returning a 'Commit' value of true signals to commit the transaction. + /// The value retured from the conditional action. + public static (bool Commit, T Value) ExecuteTransactionConditional( + this SqlConnection connection, + IsolationLevel isolationLevel, + Func conditionalAction) + => connection.ExecuteTransactionConditional(isolationLevel, null, conditionalAction); + + /// + /// Begins a transaction before executing the action. Commits if there are no exceptions and the conditional action returns true. Otherwise rolls-back the transaction. + /// + /// The connection to transact with. + /// The isolation level for the transaction. + /// The handler to execute while a transaction is pending. Returning true signals to commit the transaction. + /// True if committed. + public static bool ExecuteTransactionConditional( + this SqlConnection connection, + IsolationLevel isolationLevel, + Func conditionalAction) + => connection.ExecuteTransactionConditional(isolationLevel, null, conditionalAction); + + /// + /// Begins a transaction before executing the action. Commits if there are no exceptions. Otherwise rolls-back the transaction. + /// + /// The value returned from the action. + /// The connection to transact with. + /// The isolation level for the transaction. + /// The handler to execute while a transaction is pending. + /// The value of the action. + public static T ExecuteTransaction( + this SqlConnection connection, + IsolationLevel isolationLevel, + Func action) + => connection.ExecuteTransaction(isolationLevel, null, action); + + /// + /// Begins a transaction before executing the action. Commits if there are no exceptions. Otherwise rolls-back the transaction. + /// + /// The connection to transact with. + /// The isolation level for the transaction. + /// The handler to execute while a transaction is pending. + public static void ExecuteTransaction( + this SqlConnection connection, + IsolationLevel isolationLevel, + Action action) + => connection.ExecuteTransaction(isolationLevel, null, action); + + /// + /// Begins a transaction before executing the action. Commits if there are no exceptions and the 'Commit' value from the action is true. Otherwise rolls-back the transaction. + /// + /// The value returned from the action. + /// The connection to transact with. + /// The isolation level for the transaction. + /// The handler to execute while a transaction is pending. Returning a 'Commit' value of true signals to commit the transaction. + /// The value of the awaited action. + public static Task<(bool Commit, T Value)> ExecuteTransactionConditionalAsync( + this SqlConnection connection, + IsolationLevel isolationLevel, + Func> conditionalAction) + => connection.ExecuteTransactionConditionalAsync(isolationLevel, null, conditionalAction); + + /// + /// Begins a transaction before executing the action. Commits if there are no exceptions and the value from the action is true. Otherwise rolls-back the transaction. + /// + /// The connection to transact with. + /// The isolation level for the transaction. + /// The handler to execute while a transaction is pending. Returning true signals to commit the transaction. + /// The value of the awaited action. + public static Task ExecuteTransactionConditionalAsync( + this SqlConnection connection, + IsolationLevel isolationLevel, + Func> conditionalAction) + => connection.ExecuteTransactionConditionalAsync(isolationLevel, null, conditionalAction); + + /// + /// Begins a transaction before executing the action. Commits if there are no exceptions. Otherwise rolls-back the transaction. + /// + /// The value returned from the action. + /// The connection to transact with. + /// The isolation level for the transaction. + /// The handler to execute while a transaction is pending. + /// The value of the awaited action. + public static Task ExecuteTransactionAsync( + this SqlConnection connection, + IsolationLevel isolationLevel, + Func> action) + => connection.ExecuteTransactionAsync(isolationLevel, null, action); + + /// + /// Begins a transaction before executing the action. Commits if there are no exceptions. Otherwise rolls-back the transaction. + /// + /// The connection to transact with. + /// The isolation level for the transaction. + /// The handler to execute while a transaction is pending. + public static Task ExecuteTransactionAsync( + this SqlConnection connection, + IsolationLevel isolationLevel, + Func action) + => connection.ExecuteTransactionAsync(isolationLevel, null, action); + + #endregion + + #region Unspecified Isolation Level + /// + /// Begins a transaction before executing the action. Commits if there are no exceptions, the 'Commit' value from the action is true and the optional cancellation token has not been cancelled. Otherwise rolls-back the transaction. + /// + /// The value returned from the action. + /// The connection to transact with. + /// A optional token that if cancelled will cause this transaction to be aborted or rolled-back. + /// The handler to execute while a transaction is pending. Returning a 'Commit' value of true signals to commit the transaction. + /// The value retured from the conditional action. + public static (bool Commit, T Value) ExecuteTransactionConditional( + this SqlConnection connection, + CancellationToken? token, + Func conditionalAction) + => connection.ExecuteTransactionConditional(IsolationLevel.Unspecified, token, conditionalAction); + + /// + /// Begins a transaction before executing the action. Commits if there are no exceptions, the conditional action returns true, and the optional cancellation token is not cancelled. Otherwise rolls-back the transaction. + /// + /// The connection to transact with. + /// A optional token that if cancelled will cause this transaction to be aborted or rolled-back. + /// The handler to execute while a transaction is pending. Returning true signals to commit the transaction. + /// True if committed. + public static bool ExecuteTransactionConditional( + this SqlConnection connection, + CancellationToken? token, + Func conditionalAction) + => connection.ExecuteTransactionConditional(IsolationLevel.Unspecified, token, conditionalAction); + + /// + /// Begins a transaction before executing the action. Commits if there are no exceptions and the optional provided token is not cancelled. Otherwise rolls-back the transaction. + /// + /// The value returned from the action. + /// The connection to transact with. + /// A optional token that if cancelled will cause this transaction to be aborted or rolled-back. + /// The handler to execute while a transaction is pending. + /// The value of the action. + public static T ExecuteTransaction( + this SqlConnection connection, + CancellationToken? token, + Func action) + => connection.ExecuteTransaction(IsolationLevel.Unspecified, token, action); + + /// + /// Begins a transaction before executing the action. Commits if there are no exceptions and the optional provided token is not cancelled. Otherwise rolls-back the transaction. + /// + /// The connection to transact with. + /// A optional token that if cancelled will cause this transaction to be aborted or rolled-back. + /// The handler to execute while a transaction is pending. + public static void ExecuteTransaction( + this SqlConnection connection, + CancellationToken? token, + Action action) + => connection.ExecuteTransaction(IsolationLevel.Unspecified, token, action); + + /// + /// Begins a transaction before executing the action. Commits if there are no exceptions, the 'Commit' value from the action is true, and the optional provided token is not cancelled. Otherwise rolls-back the transaction. + /// + /// The value returned from the action. + /// The connection to transact with. + /// A optional token that if cancelled will cause this transaction to be aborted or rolled-back. + /// The handler to execute while a transaction is pending. Returning a 'Commit' value of true signals to commit the transaction. + /// The value of the awaited action. + public static Task<(bool Commit, T Value)> ExecuteTransactionConditionalAsync( + this SqlConnection connection, + CancellationToken? token, + Func> conditionalAction) + => connection.ExecuteTransactionConditionalAsync(IsolationLevel.Unspecified, token, conditionalAction); + + /// + /// Begins a transaction before executing the action. Commits if there are no exceptions, the value from the action is true, and the optional provided token is not cancelled. Otherwise rolls-back the transaction. + /// + /// The connection to transact with. + /// A optional token that if cancelled will cause this transaction to be aborted or rolled-back. + /// The handler to execute while a transaction is pending. Returning true signals to commit the transaction. + /// The value of the awaited action. + public static Task ExecuteTransactionConditionalAsync( + this SqlConnection connection, + CancellationToken? token, + Func> conditionalAction) + => connection.ExecuteTransactionConditionalAsync(IsolationLevel.Unspecified, token, conditionalAction); + + /// + /// Begins a transaction before executing the action. Commits if there are no exceptions and the optional provided token is not cancelled. Otherwise rolls-back the transaction. + /// + /// The value returned from the action. + /// The connection to transact with. + /// A optional token that if cancelled will cause this transaction to be aborted or rolled-back. + /// The handler to execute while a transaction is pending. + /// The value of the awaited action. + public static Task ExecuteTransactionAsync( + this SqlConnection connection, + CancellationToken? token, + Func> action) + => connection.ExecuteTransactionAsync(IsolationLevel.Unspecified, token, action); + + /// + /// Begins a transaction before executing the action. Commits if there are no exceptions and the optional provided token is not cancelled. Otherwise rolls-back the transaction. + /// + /// The connection to transact with. + /// A optional token that if cancelled will cause this transaction to be aborted or rolled-back. + /// The handler to execute while a transaction is pending. + public static Task ExecuteTransactionAsync( + this SqlConnection connection, + CancellationToken? token, + Func action) + => connection.ExecuteTransactionAsync(IsolationLevel.Unspecified, token, action); + + #endregion + + #region Defaults Only + /// + /// Begins a transaction before executing the action. Commits if there are no exceptions and 'Commit' value from the action is true. Otherwise rolls-back the transaction. + /// + /// The value returned from the action. + /// The connection to transact with. + /// The handler to execute while a transaction is pending. Returning a 'Commit' value of true signals to commit the transaction. + /// The value retured from the conditional action. + public static (bool Commit, T Value) ExecuteTransactionConditional( + this SqlConnection connection, + Func conditionalAction) + => connection.ExecuteTransactionConditional(IsolationLevel.Unspecified, null, conditionalAction); + + /// + /// Begins a transaction before executing the action. Commits if there are no exceptions and the conditional action returns true. Otherwise rolls-back the transaction. + /// + /// The connection to transact with. + /// The handler to execute while a transaction is pending. Returning true signals to commit the transaction. + /// True if committed. + public static bool ExecuteTransactionConditional( + this SqlConnection connection, + Func conditionalAction) + => connection.ExecuteTransactionConditional(IsolationLevel.Unspecified, null, conditionalAction); + + /// + /// Begins a transaction before executing the action. Commits if there are no exceptions. Otherwise rolls-back the transaction. + /// + /// The value returned from the action. + /// The connection to transact with. + /// The handler to execute while a transaction is pending. + /// The value of the action. + public static T ExecuteTransaction( + this SqlConnection connection, + Func action) + => connection.ExecuteTransaction(IsolationLevel.Unspecified, null, action); + + /// + /// Begins a transaction before executing the action. Commits if there are no exceptions. Otherwise rolls-back the transaction. + /// + /// The connection to transact with. + /// The handler to execute while a transaction is pending. + public static void ExecuteTransaction( + this SqlConnection connection, + Action action) + => connection.ExecuteTransaction(IsolationLevel.Unspecified, null, action); + + /// + /// Begins a transaction before executing the action. Commits if there are no exceptions and the 'Commit' value from the action is true. Otherwise rolls-back the transaction. + /// + /// The value returned from the action. + /// The connection to transact with. + /// The handler to execute while a transaction is pending. Returning a 'Commit' value of true signals to commit the transaction. + /// The value of the awaited action. + public static Task<(bool Commit, T Value)> ExecuteTransactionConditionalAsync( + this SqlConnection connection, + Func> conditionalAction) + => connection.ExecuteTransactionConditionalAsync(IsolationLevel.Unspecified, null, conditionalAction); + + /// + /// Begins a transaction before executing the action. Commits if there are no exceptions and the value from the action is true. Otherwise rolls-back the transaction. + /// + /// The connection to transact with. + /// The handler to execute while a transaction is pending. Returning true signals to commit the transaction. + /// The value of the awaited action. + public static Task ExecuteTransactionConditionalAsync( + this SqlConnection connection, + Func> conditionalAction) + => connection.ExecuteTransactionConditionalAsync(IsolationLevel.Unspecified, null, conditionalAction); + + /// + /// Begins a transaction before executing the action. Commits if there are no exceptions. Otherwise rolls-back the transaction. + /// + /// The value returned from the action. + /// The connection to transact with. + /// The handler to execute while a transaction is pending. + /// The value of the awaited action. + public static Task ExecuteTransactionAsync( + this SqlConnection connection, + Func> action) + => connection.ExecuteTransactionAsync(IsolationLevel.Unspecified, null, action); + + /// + /// Begins a transaction before executing the action. Commits if there are no exceptions. Otherwise rolls-back the transaction. + /// + /// The connection to transact with. + /// The handler to execute while a transaction is pending. + public static Task ExecuteTransactionAsync( + this SqlConnection connection, + Func action) + => connection.ExecuteTransactionAsync(IsolationLevel.Unspecified, null, action); + + #endregion + + #endregion + } + +} diff --git a/SqlClient/Extensions.cs b/SqlClient/Extensions.cs index 15e5a2e..d29684f 100644 --- a/SqlClient/Extensions.cs +++ b/SqlClient/Extensions.cs @@ -8,49 +8,19 @@ namespace Open.Database.Extensions.SqlClient /// /// SqlClient extensions for building a command and retrieving data using best practices. /// - public static class Extensions + public static partial class Extensions { - /// - /// Shortcut for creating an SqlCommand from any SqlConnection. - /// - /// The connection to create a command from. - /// The command type. Text, StoredProcedure, or TableDirect. - /// The command text or stored procedure name to use. - /// The number of seconds to wait before the command times out. - /// The created SqlCommand. - public static SqlCommand CreateCommand(this SqlConnection connection, - CommandType type, string commandText, int secondsTimeout = CommandTimeout.DEFAULT_SECONDS) - { - var command = connection.CreateCommand(); - command.CommandType = type; - command.CommandText = commandText; - command.CommandTimeout = secondsTimeout; - - return command; - } - - /// - /// Shortcut for creating an SqlCommand from any SqlConnection. - /// - /// The connection to create a command from. - /// The command text or stored procedure name to use. - /// The number of seconds to wait before the command times out. - /// The created SqlCommand. - public static SqlCommand CreateStoredProcedureCommand(this SqlConnection connection, - string commandText, int secondsTimeout = CommandTimeout.DEFAULT_SECONDS) - => connection.CreateCommand(CommandType.StoredProcedure, commandText, secondsTimeout); - - /// - /// Shortcut for adding command parameter. - /// - /// The command to add a parameter to. - /// The name of the parameter. - /// The value of the parameter. - /// The DbType of the parameter. - /// The direction of the parameter. - /// The created IDbDataParameter. - public static SqlParameter AddParameter(this SqlCommand target, + /// + /// Shortcut for adding command parameter. + /// + /// The command to add a parameter to. + /// The name of the parameter. + /// The value of the parameter. + /// The DbType of the parameter. + /// The direction of the parameter. + /// The created IDbDataParameter. + public static SqlParameter AddParameter(this SqlCommand target, string name, object value, SqlDbType type, ParameterDirection direction = ParameterDirection.Input) { var p = target.AddParameterType(name, type, direction); @@ -88,75 +58,6 @@ public static SqlParameter AddParameterType(this IDbCommand target, string name, { return AddParameterType((SqlCommand)target, name, type); } - - /// - /// Creates an ExpressiveSqlCommand for subsequent configuration and execution. - /// - /// The connection to execute the command on. - /// The command text or stored procedure name to use. - /// The command type. - /// The resultant ExpressiveSqlCommand. - public static ExpressiveSqlCommand Command( - this SqlConnection target, - string command, CommandType type = CommandType.Text) - => new ExpressiveSqlCommand(target, type, command); - - /// - /// Creates an ExpressiveSqlCommand with command type set to StoredProcedure for subsequent configuration and execution. - /// - /// The connection to execute the command on. - /// The command text or stored procedure name to use. - /// The resultant ExpressiveSqlCommand. - public static ExpressiveSqlCommand StoredProcedure( - this SqlConnection target, - string command) - => new ExpressiveSqlCommand(target, CommandType.StoredProcedure, command); - - /// - /// Creates an ExpressiveSqlCommand for subsequent configuration and execution. - /// - /// The connection factory to generate a commands from. - /// The command text or stored procedure name to use. - /// The command type. - /// The resultant ExpressiveSqlCommand. - public static ExpressiveSqlCommand Command( - this IDbConnectionFactory target, - string command, CommandType type = CommandType.Text) - => new ExpressiveSqlCommand(target, type, command); - - /// - /// Creates an ExpressiveSqlCommand with command type set to StoredProcedure for subsequent configuration and execution. - /// - /// The connection factory to generate a commands from. - /// The command text or stored procedure name to use. - /// The resultant ExpressiveSqlCommand. - public static ExpressiveSqlCommand StoredProcedure( - this IDbConnectionFactory target, - string command) - => new ExpressiveSqlCommand(target, CommandType.StoredProcedure, command); - - /// - /// Creates an ExpressiveSqlCommand for subsequent configuration and execution. - /// - /// The connection factory to generate a commands from. - /// The command text or stored procedure name to use. - /// The command type. - /// The resultant ExpressiveSqlCommand. - public static ExpressiveSqlCommand Command( - this Func target, - string command, CommandType type = CommandType.Text) - => Command(new DbConnectionFactory(target), command, type); - - /// - /// Creates an ExpressiveSqlCommand with command type set to StoredProcedure for subsequent configuration and execution. - /// - /// The connection factory to generate a commands from. - /// The command text or stored procedure name to use. - /// The resultant ExpressiveSqlCommand. - public static ExpressiveSqlCommand StoredProcedure( - this Func target, - string command) - => StoredProcedure(new DbConnectionFactory(target), command); - + } } diff --git a/api/.manifest b/api/.manifest index 178360e..c8323ff 100644 --- a/api/.manifest +++ b/api/.manifest @@ -7,8 +7,8 @@ "Open.Database.Extensions.DbConnectionFactory`1.Create": "Open.Database.Extensions.DbConnectionFactory-1.yml", "Open.Database.Extensions.DbConnectionFactory`1.Open#Database#Extensions#IDbConnectionFactory#Create": "Open.Database.Extensions.DbConnectionFactory-1.yml", "Open.Database.Extensions.ExpressiveCommandBase`4": "Open.Database.Extensions.ExpressiveCommandBase-4.yml", - "Open.Database.Extensions.ExpressiveCommandBase`4.#ctor(`0,System.Data.CommandType,System.String,System.Collections.Generic.List{Open.Database.Extensions.ExpressiveCommandBase{`0,`1,`2,`3}.Param})": "Open.Database.Extensions.ExpressiveCommandBase-4.yml", - "Open.Database.Extensions.ExpressiveCommandBase`4.#ctor(Open.Database.Extensions.IDbConnectionFactory{`0},System.Data.CommandType,System.String,System.Collections.Generic.List{Open.Database.Extensions.ExpressiveCommandBase{`0,`1,`2,`3}.Param})": "Open.Database.Extensions.ExpressiveCommandBase-4.yml", + "Open.Database.Extensions.ExpressiveCommandBase`4.#ctor(`0,System.Data.IDbTransaction,System.Data.CommandType,System.String,System.Collections.Generic.IEnumerable{Open.Database.Extensions.ExpressiveCommandBase{`0,`1,`2,`3}.Param})": "Open.Database.Extensions.ExpressiveCommandBase-4.yml", + "Open.Database.Extensions.ExpressiveCommandBase`4.#ctor(Open.Database.Extensions.IDbConnectionFactory{`0},System.Data.CommandType,System.String,System.Collections.Generic.IEnumerable{Open.Database.Extensions.ExpressiveCommandBase{`0,`1,`2,`3}.Param})": "Open.Database.Extensions.ExpressiveCommandBase-4.yml", "Open.Database.Extensions.ExpressiveCommandBase`4.AddParam(System.String)": "Open.Database.Extensions.ExpressiveCommandBase-4.yml", "Open.Database.Extensions.ExpressiveCommandBase`4.AddParam(System.String,System.Object)": "Open.Database.Extensions.ExpressiveCommandBase-4.yml", "Open.Database.Extensions.ExpressiveCommandBase`4.AddParam(System.String,System.Object,`2)": "Open.Database.Extensions.ExpressiveCommandBase-4.yml", @@ -73,18 +73,17 @@ "Open.Database.Extensions.ExpressiveCommandBase`4.ToArray``1(System.Func{System.Data.IDataRecord,``0})": "Open.Database.Extensions.ExpressiveCommandBase-4.yml", "Open.Database.Extensions.ExpressiveCommandBase`4.ToList``1(System.Func{System.Data.IDataRecord,``0})": "Open.Database.Extensions.ExpressiveCommandBase-4.yml", "Open.Database.Extensions.ExpressiveCommandBase`4.ToTargetBlock``1(System.Threading.Tasks.Dataflow.ITargetBlock{``0},System.Func{System.Data.IDataRecord,``0})": "Open.Database.Extensions.ExpressiveCommandBase-4.yml", + "Open.Database.Extensions.ExpressiveCommandBase`4.Transaction": "Open.Database.Extensions.ExpressiveCommandBase-4.yml", "Open.Database.Extensions.ExpressiveCommandBase`4.Type": "Open.Database.Extensions.ExpressiveCommandBase-4.yml", - "Open.Database.Extensions.ExpressiveCommandBase`4.UsingConnection(System.Action{`0})": "Open.Database.Extensions.ExpressiveCommandBase-4.yml", - "Open.Database.Extensions.ExpressiveCommandBase`4.UsingConnection``1(System.Func{`0,``0})": "Open.Database.Extensions.ExpressiveCommandBase-4.yml", + "Open.Database.Extensions.ExpressiveCommandBase`4.UsingConnection(System.Action{`0,System.Data.IDbTransaction})": "Open.Database.Extensions.ExpressiveCommandBase-4.yml", + "Open.Database.Extensions.ExpressiveCommandBase`4.UsingConnection``1(System.Func{`0,System.Data.IDbTransaction,``0})": "Open.Database.Extensions.ExpressiveCommandBase-4.yml", "Open.Database.Extensions.ExpressiveDbCommand": "Open.Database.Extensions.ExpressiveDbCommand.yml", - "Open.Database.Extensions.ExpressiveDbCommand.#ctor(Open.Database.Extensions.IDbConnectionFactory{System.Data.Common.DbConnection},System.Data.CommandType,System.String,Open.Database.Extensions.ExpressiveCommandBase{System.Data.Common.DbConnection,System.Data.Common.DbCommand,System.Data.DbType,Open.Database.Extensions.ExpressiveDbCommand}.Param[])": "Open.Database.Extensions.ExpressiveDbCommand.yml", - "Open.Database.Extensions.ExpressiveDbCommand.#ctor(Open.Database.Extensions.IDbConnectionFactory{System.Data.Common.DbConnection},System.Data.CommandType,System.String,System.Collections.Generic.List{Open.Database.Extensions.ExpressiveCommandBase{System.Data.Common.DbConnection,System.Data.Common.DbCommand,System.Data.DbType,Open.Database.Extensions.ExpressiveDbCommand}.Param})": "Open.Database.Extensions.ExpressiveDbCommand.yml", - "Open.Database.Extensions.ExpressiveDbCommand.#ctor(System.Data.Common.DbConnection,System.Data.CommandType,System.String,Open.Database.Extensions.ExpressiveCommandBase{System.Data.Common.DbConnection,System.Data.Common.DbCommand,System.Data.DbType,Open.Database.Extensions.ExpressiveDbCommand}.Param[])": "Open.Database.Extensions.ExpressiveDbCommand.yml", - "Open.Database.Extensions.ExpressiveDbCommand.#ctor(System.Data.Common.DbConnection,System.Data.CommandType,System.String,System.Collections.Generic.List{Open.Database.Extensions.ExpressiveCommandBase{System.Data.Common.DbConnection,System.Data.Common.DbCommand,System.Data.DbType,Open.Database.Extensions.ExpressiveDbCommand}.Param})": "Open.Database.Extensions.ExpressiveDbCommand.yml", + "Open.Database.Extensions.ExpressiveDbCommand.#ctor(Open.Database.Extensions.IDbConnectionFactory{System.Data.Common.DbConnection},System.Data.CommandType,System.String,System.Collections.Generic.IEnumerable{Open.Database.Extensions.ExpressiveCommandBase{System.Data.Common.DbConnection,System.Data.Common.DbCommand,System.Data.DbType,Open.Database.Extensions.ExpressiveDbCommand}.Param})": "Open.Database.Extensions.ExpressiveDbCommand.yml", + "Open.Database.Extensions.ExpressiveDbCommand.#ctor(System.Data.Common.DbConnection,System.Data.Common.DbTransaction,System.Data.CommandType,System.String,System.Collections.Generic.IEnumerable{Open.Database.Extensions.ExpressiveCommandBase{System.Data.Common.DbConnection,System.Data.Common.DbCommand,System.Data.DbType,Open.Database.Extensions.ExpressiveDbCommand}.Param})": "Open.Database.Extensions.ExpressiveDbCommand.yml", "Open.Database.Extensions.ExpressiveDbCommand.AddParams(System.Data.Common.DbCommand)": "Open.Database.Extensions.ExpressiveDbCommand.yml", "Open.Database.Extensions.ExpressiveDbCommandBase`4": "Open.Database.Extensions.ExpressiveDbCommandBase-4.yml", - "Open.Database.Extensions.ExpressiveDbCommandBase`4.#ctor(`0,System.Data.CommandType,System.String,System.Collections.Generic.List{Open.Database.Extensions.ExpressiveCommandBase{`0,`1,`2,`3}.Param})": "Open.Database.Extensions.ExpressiveDbCommandBase-4.yml", - "Open.Database.Extensions.ExpressiveDbCommandBase`4.#ctor(Open.Database.Extensions.IDbConnectionFactory{`0},System.Data.CommandType,System.String,System.Collections.Generic.List{Open.Database.Extensions.ExpressiveCommandBase{`0,`1,`2,`3}.Param})": "Open.Database.Extensions.ExpressiveDbCommandBase-4.yml", + "Open.Database.Extensions.ExpressiveDbCommandBase`4.#ctor(`0,System.Data.IDbTransaction,System.Data.CommandType,System.String,System.Collections.Generic.IEnumerable{Open.Database.Extensions.ExpressiveCommandBase{`0,`1,`2,`3}.Param})": "Open.Database.Extensions.ExpressiveDbCommandBase-4.yml", + "Open.Database.Extensions.ExpressiveDbCommandBase`4.#ctor(Open.Database.Extensions.IDbConnectionFactory{`0},System.Data.CommandType,System.String,System.Collections.Generic.IEnumerable{Open.Database.Extensions.ExpressiveCommandBase{`0,`1,`2,`3}.Param})": "Open.Database.Extensions.ExpressiveDbCommandBase-4.yml", "Open.Database.Extensions.ExpressiveDbCommandBase`4.AsSourceBlockAsync``1(System.Collections.Generic.IEnumerable{System.Collections.Generic.KeyValuePair{System.String,System.String}})": "Open.Database.Extensions.ExpressiveDbCommandBase-4.yml", "Open.Database.Extensions.ExpressiveDbCommandBase`4.AsSourceBlockAsync``1(System.Collections.Generic.IEnumerable{System.ValueTuple{System.String,System.String}})": "Open.Database.Extensions.ExpressiveDbCommandBase-4.yml", "Open.Database.Extensions.ExpressiveDbCommandBase`4.AsSourceBlockAsync``1(System.Func{System.Data.IDataRecord,``0})": "Open.Database.Extensions.ExpressiveDbCommandBase-4.yml", @@ -127,11 +126,20 @@ "Open.Database.Extensions.Extensions.AsEnumerable(System.Data.IDataReader,System.Int32,System.Int32[])": "Open.Database.Extensions.Extensions.yml", "Open.Database.Extensions.Extensions.Command(Open.Database.Extensions.IDbConnectionFactory{System.Data.Common.DbConnection},System.String,System.Data.CommandType)": "Open.Database.Extensions.Extensions.yml", "Open.Database.Extensions.Extensions.Command(System.Data.Common.DbConnection,System.String,System.Data.CommandType)": "Open.Database.Extensions.Extensions.yml", + "Open.Database.Extensions.Extensions.Command(System.Data.Common.DbTransaction,System.String,System.Data.CommandType)": "Open.Database.Extensions.Extensions.yml", "Open.Database.Extensions.Extensions.Command(System.Func{System.Data.Common.DbConnection},System.String,System.Data.CommandType)": "Open.Database.Extensions.Extensions.yml", "Open.Database.Extensions.Extensions.CreateCommand(System.Data.Common.DbConnection,System.Data.CommandType,System.String,System.Int32)": "Open.Database.Extensions.Extensions.yml", + "Open.Database.Extensions.Extensions.CreateCommand(System.Data.Common.DbTransaction,System.Data.CommandType,System.String,System.Int32)": "Open.Database.Extensions.Extensions.yml", "Open.Database.Extensions.Extensions.CreateCommand(System.Data.IDbConnection,System.Data.CommandType,System.String,System.Int32)": "Open.Database.Extensions.Extensions.yml", + "Open.Database.Extensions.Extensions.CreateCommand(System.Data.IDbTransaction,System.Data.CommandType,System.String,System.Int32)": "Open.Database.Extensions.Extensions.yml", "Open.Database.Extensions.Extensions.CreateStoredProcedureCommand(System.Data.Common.DbConnection,System.String,System.Int32)": "Open.Database.Extensions.Extensions.yml", + "Open.Database.Extensions.Extensions.CreateStoredProcedureCommand(System.Data.Common.DbTransaction,System.String,System.Int32)": "Open.Database.Extensions.Extensions.yml", "Open.Database.Extensions.Extensions.CreateStoredProcedureCommand(System.Data.IDbConnection,System.String,System.Int32)": "Open.Database.Extensions.Extensions.yml", + "Open.Database.Extensions.Extensions.CreateStoredProcedureCommand(System.Data.IDbTransaction,System.String,System.Int32)": "Open.Database.Extensions.Extensions.yml", + "Open.Database.Extensions.Extensions.CreateTextCommand(System.Data.Common.DbConnection,System.String,System.Int32)": "Open.Database.Extensions.Extensions.yml", + "Open.Database.Extensions.Extensions.CreateTextCommand(System.Data.Common.DbTransaction,System.String,System.Int32)": "Open.Database.Extensions.Extensions.yml", + "Open.Database.Extensions.Extensions.CreateTextCommand(System.Data.IDbConnection,System.String,System.Int32)": "Open.Database.Extensions.Extensions.yml", + "Open.Database.Extensions.Extensions.CreateTextCommand(System.Data.IDbTransaction,System.String,System.Int32)": "Open.Database.Extensions.Extensions.yml", "Open.Database.Extensions.Extensions.DBNullToNull(System.Collections.Generic.IEnumerable{System.Object})": "Open.Database.Extensions.Extensions.yml", "Open.Database.Extensions.Extensions.DBNullToNull(System.Object[])": "Open.Database.Extensions.Extensions.yml", "Open.Database.Extensions.Extensions.DequeueEach``1(System.Collections.Generic.Queue{``0})": "Open.Database.Extensions.Extensions.yml", @@ -141,14 +149,38 @@ "Open.Database.Extensions.Extensions.ExecuteReader``1(System.Data.IDbCommand,System.Func{System.Data.IDataReader,``0},System.Data.CommandBehavior)": "Open.Database.Extensions.Extensions.yml", "Open.Database.Extensions.Extensions.ExecuteReaderAsync(System.Data.Common.DbCommand,System.Func{System.Data.Common.DbDataReader,System.Threading.Tasks.Task},System.Data.CommandBehavior,System.Nullable{System.Threading.CancellationToken})": "Open.Database.Extensions.Extensions.yml", "Open.Database.Extensions.Extensions.ExecuteReaderAsync``1(System.Data.Common.DbCommand,System.Func{System.Data.Common.DbDataReader,System.Threading.Tasks.Task{``0}},System.Data.CommandBehavior,System.Nullable{System.Threading.CancellationToken})": "Open.Database.Extensions.Extensions.yml", - "Open.Database.Extensions.Extensions.ExecuteTransaction``1(``0,System.Action{``0},System.Nullable{System.Threading.CancellationToken})": "Open.Database.Extensions.Extensions.yml", - "Open.Database.Extensions.Extensions.ExecuteTransaction``2(``0,System.Func{``0,``1},System.Nullable{System.Threading.CancellationToken})": "Open.Database.Extensions.Extensions.yml", - "Open.Database.Extensions.Extensions.ExecuteTransactionAsync``1(``0,System.Func{``0,System.Threading.Tasks.Task},System.Nullable{System.Threading.CancellationToken})": "Open.Database.Extensions.Extensions.yml", - "Open.Database.Extensions.Extensions.ExecuteTransactionAsync``2(``0,System.Func{``0,System.Threading.Tasks.Task{``1}},System.Nullable{System.Threading.CancellationToken})": "Open.Database.Extensions.Extensions.yml", - "Open.Database.Extensions.Extensions.ExecuteTransactionConditional``1(``0,System.Func{``0,System.Boolean},System.Nullable{System.Threading.CancellationToken})": "Open.Database.Extensions.Extensions.yml", - "Open.Database.Extensions.Extensions.ExecuteTransactionConditional``2(``0,System.Func{``0,System.ValueTuple{System.Boolean,``1}},System.Nullable{System.Threading.CancellationToken})": "Open.Database.Extensions.Extensions.yml", - "Open.Database.Extensions.Extensions.ExecuteTransactionConditionalAsync``2(``0,System.Func{``0,System.Threading.Tasks.Task{System.Boolean}},System.Nullable{System.Threading.CancellationToken})": "Open.Database.Extensions.Extensions.yml", - "Open.Database.Extensions.Extensions.ExecuteTransactionConditionalAsync``2(``0,System.Func{``0,System.Threading.Tasks.Task{System.ValueTuple{System.Boolean,``1}}},System.Nullable{System.Threading.CancellationToken})": "Open.Database.Extensions.Extensions.yml", + "Open.Database.Extensions.Extensions.ExecuteTransaction(System.Data.Common.DbConnection,System.Action{System.Data.Common.DbTransaction})": "Open.Database.Extensions.Extensions.yml", + "Open.Database.Extensions.Extensions.ExecuteTransaction(System.Data.Common.DbConnection,System.Data.IsolationLevel,System.Action{System.Data.Common.DbTransaction})": "Open.Database.Extensions.Extensions.yml", + "Open.Database.Extensions.Extensions.ExecuteTransaction(System.Data.Common.DbConnection,System.Data.IsolationLevel,System.Nullable{System.Threading.CancellationToken},System.Action{System.Data.Common.DbTransaction})": "Open.Database.Extensions.Extensions.yml", + "Open.Database.Extensions.Extensions.ExecuteTransaction(System.Data.Common.DbConnection,System.Nullable{System.Threading.CancellationToken},System.Action{System.Data.Common.DbTransaction})": "Open.Database.Extensions.Extensions.yml", + "Open.Database.Extensions.Extensions.ExecuteTransaction``1(System.Data.Common.DbConnection,System.Data.IsolationLevel,System.Func{System.Data.Common.DbTransaction,``0})": "Open.Database.Extensions.Extensions.yml", + "Open.Database.Extensions.Extensions.ExecuteTransaction``1(System.Data.Common.DbConnection,System.Data.IsolationLevel,System.Nullable{System.Threading.CancellationToken},System.Func{System.Data.Common.DbTransaction,``0})": "Open.Database.Extensions.Extensions.yml", + "Open.Database.Extensions.Extensions.ExecuteTransaction``1(System.Data.Common.DbConnection,System.Func{System.Data.Common.DbTransaction,``0})": "Open.Database.Extensions.Extensions.yml", + "Open.Database.Extensions.Extensions.ExecuteTransaction``1(System.Data.Common.DbConnection,System.Nullable{System.Threading.CancellationToken},System.Func{System.Data.Common.DbTransaction,``0})": "Open.Database.Extensions.Extensions.yml", + "Open.Database.Extensions.Extensions.ExecuteTransactionAsync(System.Data.Common.DbConnection,System.Data.IsolationLevel,System.Func{System.Data.Common.DbTransaction,System.Threading.Tasks.Task})": "Open.Database.Extensions.Extensions.yml", + "Open.Database.Extensions.Extensions.ExecuteTransactionAsync(System.Data.Common.DbConnection,System.Data.IsolationLevel,System.Nullable{System.Threading.CancellationToken},System.Func{System.Data.Common.DbTransaction,System.Threading.Tasks.Task})": "Open.Database.Extensions.Extensions.yml", + "Open.Database.Extensions.Extensions.ExecuteTransactionAsync(System.Data.Common.DbConnection,System.Func{System.Data.Common.DbTransaction,System.Threading.Tasks.Task})": "Open.Database.Extensions.Extensions.yml", + "Open.Database.Extensions.Extensions.ExecuteTransactionAsync(System.Data.Common.DbConnection,System.Nullable{System.Threading.CancellationToken},System.Func{System.Data.Common.DbTransaction,System.Threading.Tasks.Task})": "Open.Database.Extensions.Extensions.yml", + "Open.Database.Extensions.Extensions.ExecuteTransactionAsync``1(System.Data.Common.DbConnection,System.Data.IsolationLevel,System.Func{System.Data.Common.DbTransaction,System.Threading.Tasks.Task{``0}})": "Open.Database.Extensions.Extensions.yml", + "Open.Database.Extensions.Extensions.ExecuteTransactionAsync``1(System.Data.Common.DbConnection,System.Data.IsolationLevel,System.Nullable{System.Threading.CancellationToken},System.Func{System.Data.Common.DbTransaction,System.Threading.Tasks.Task{``0}})": "Open.Database.Extensions.Extensions.yml", + "Open.Database.Extensions.Extensions.ExecuteTransactionAsync``1(System.Data.Common.DbConnection,System.Func{System.Data.Common.DbTransaction,System.Threading.Tasks.Task{``0}})": "Open.Database.Extensions.Extensions.yml", + "Open.Database.Extensions.Extensions.ExecuteTransactionAsync``1(System.Data.Common.DbConnection,System.Nullable{System.Threading.CancellationToken},System.Func{System.Data.Common.DbTransaction,System.Threading.Tasks.Task{``0}})": "Open.Database.Extensions.Extensions.yml", + "Open.Database.Extensions.Extensions.ExecuteTransactionConditional(System.Data.Common.DbConnection,System.Data.IsolationLevel,System.Func{System.Data.Common.DbTransaction,System.Boolean})": "Open.Database.Extensions.Extensions.yml", + "Open.Database.Extensions.Extensions.ExecuteTransactionConditional(System.Data.Common.DbConnection,System.Data.IsolationLevel,System.Nullable{System.Threading.CancellationToken},System.Func{System.Data.Common.DbTransaction,System.Boolean})": "Open.Database.Extensions.Extensions.yml", + "Open.Database.Extensions.Extensions.ExecuteTransactionConditional(System.Data.Common.DbConnection,System.Func{System.Data.Common.DbTransaction,System.Boolean})": "Open.Database.Extensions.Extensions.yml", + "Open.Database.Extensions.Extensions.ExecuteTransactionConditional(System.Data.Common.DbConnection,System.Nullable{System.Threading.CancellationToken},System.Func{System.Data.Common.DbTransaction,System.Boolean})": "Open.Database.Extensions.Extensions.yml", + "Open.Database.Extensions.Extensions.ExecuteTransactionConditional``1(System.Data.Common.DbConnection,System.Data.IsolationLevel,System.Func{System.Data.Common.DbTransaction,System.ValueTuple{System.Boolean,``0}})": "Open.Database.Extensions.Extensions.yml", + "Open.Database.Extensions.Extensions.ExecuteTransactionConditional``1(System.Data.Common.DbConnection,System.Data.IsolationLevel,System.Nullable{System.Threading.CancellationToken},System.Func{System.Data.Common.DbTransaction,System.ValueTuple{System.Boolean,``0}})": "Open.Database.Extensions.Extensions.yml", + "Open.Database.Extensions.Extensions.ExecuteTransactionConditional``1(System.Data.Common.DbConnection,System.Func{System.Data.Common.DbTransaction,System.ValueTuple{System.Boolean,``0}})": "Open.Database.Extensions.Extensions.yml", + "Open.Database.Extensions.Extensions.ExecuteTransactionConditional``1(System.Data.Common.DbConnection,System.Nullable{System.Threading.CancellationToken},System.Func{System.Data.Common.DbTransaction,System.ValueTuple{System.Boolean,``0}})": "Open.Database.Extensions.Extensions.yml", + "Open.Database.Extensions.Extensions.ExecuteTransactionConditionalAsync(System.Data.Common.DbConnection,System.Data.IsolationLevel,System.Func{System.Data.Common.DbTransaction,System.Threading.Tasks.Task{System.Boolean}})": "Open.Database.Extensions.Extensions.yml", + "Open.Database.Extensions.Extensions.ExecuteTransactionConditionalAsync(System.Data.Common.DbConnection,System.Data.IsolationLevel,System.Nullable{System.Threading.CancellationToken},System.Func{System.Data.Common.DbTransaction,System.Threading.Tasks.Task{System.Boolean}})": "Open.Database.Extensions.Extensions.yml", + "Open.Database.Extensions.Extensions.ExecuteTransactionConditionalAsync(System.Data.Common.DbConnection,System.Func{System.Data.Common.DbTransaction,System.Threading.Tasks.Task{System.Boolean}})": "Open.Database.Extensions.Extensions.yml", + "Open.Database.Extensions.Extensions.ExecuteTransactionConditionalAsync(System.Data.Common.DbConnection,System.Nullable{System.Threading.CancellationToken},System.Func{System.Data.Common.DbTransaction,System.Threading.Tasks.Task{System.Boolean}})": "Open.Database.Extensions.Extensions.yml", + "Open.Database.Extensions.Extensions.ExecuteTransactionConditionalAsync``1(System.Data.Common.DbConnection,System.Data.IsolationLevel,System.Func{System.Data.Common.DbTransaction,System.Threading.Tasks.Task{System.ValueTuple{System.Boolean,``0}}})": "Open.Database.Extensions.Extensions.yml", + "Open.Database.Extensions.Extensions.ExecuteTransactionConditionalAsync``1(System.Data.Common.DbConnection,System.Data.IsolationLevel,System.Nullable{System.Threading.CancellationToken},System.Func{System.Data.Common.DbTransaction,System.Threading.Tasks.Task{System.ValueTuple{System.Boolean,``0}}})": "Open.Database.Extensions.Extensions.yml", + "Open.Database.Extensions.Extensions.ExecuteTransactionConditionalAsync``1(System.Data.Common.DbConnection,System.Func{System.Data.Common.DbTransaction,System.Threading.Tasks.Task{System.ValueTuple{System.Boolean,``0}}})": "Open.Database.Extensions.Extensions.yml", + "Open.Database.Extensions.Extensions.ExecuteTransactionConditionalAsync``1(System.Data.Common.DbConnection,System.Nullable{System.Threading.CancellationToken},System.Func{System.Data.Common.DbTransaction,System.Threading.Tasks.Task{System.ValueTuple{System.Boolean,``0}}})": "Open.Database.Extensions.Extensions.yml", "Open.Database.Extensions.Extensions.First``1(System.Data.IDbCommand,System.Func{System.Data.IDataRecord,``0})": "Open.Database.Extensions.Extensions.yml", "Open.Database.Extensions.Extensions.FirstOrDefault``1(System.Data.IDbCommand,System.Func{System.Data.IDataRecord,``0})": "Open.Database.Extensions.Extensions.yml", "Open.Database.Extensions.Extensions.FirstOrdinalResults(System.Data.IDataReader)": "Open.Database.Extensions.Extensions.yml", @@ -224,6 +256,7 @@ "Open.Database.Extensions.Extensions.SkipThenTake``1(System.Data.IDbCommand,System.Int32,System.Int32,System.Func{System.Data.IDataRecord,``0})": "Open.Database.Extensions.Extensions.yml", "Open.Database.Extensions.Extensions.StoredProcedure(Open.Database.Extensions.IDbConnectionFactory{System.Data.Common.DbConnection},System.String)": "Open.Database.Extensions.Extensions.yml", "Open.Database.Extensions.Extensions.StoredProcedure(System.Data.Common.DbConnection,System.String)": "Open.Database.Extensions.Extensions.yml", + "Open.Database.Extensions.Extensions.StoredProcedure(System.Data.Common.DbTransaction,System.String)": "Open.Database.Extensions.Extensions.yml", "Open.Database.Extensions.Extensions.StoredProcedure(System.Func{System.Data.Common.DbConnection},System.String)": "Open.Database.Extensions.Extensions.yml", "Open.Database.Extensions.Extensions.Take``1(System.Data.IDbCommand,System.Int32,System.Func{System.Data.IDataRecord,``0})": "Open.Database.Extensions.Extensions.yml", "Open.Database.Extensions.Extensions.To``1(System.Data.DataTable,System.Collections.Generic.IEnumerable{System.Collections.Generic.KeyValuePair{System.String,System.String}},System.Boolean)": "Open.Database.Extensions.Extensions.yml", @@ -281,10 +314,8 @@ "Open.Database.Extensions.QueryResultExtensions.To``1(Open.Database.Extensions.QueryResult{System.Threading.Tasks.Dataflow.ISourceBlock{System.Object[]}},System.ValueTuple{System.String,System.String}[])": "Open.Database.Extensions.QueryResultExtensions.yml", "Open.Database.Extensions.SqlClient": "Open.Database.Extensions.SqlClient.yml", "Open.Database.Extensions.SqlClient.ExpressiveSqlCommand": "Open.Database.Extensions.SqlClient.ExpressiveSqlCommand.yml", - "Open.Database.Extensions.SqlClient.ExpressiveSqlCommand.#ctor(Open.Database.Extensions.IDbConnectionFactory{System.Data.SqlClient.SqlConnection},System.Data.CommandType,System.String,Open.Database.Extensions.ExpressiveCommandBase{System.Data.SqlClient.SqlConnection,System.Data.SqlClient.SqlCommand,System.Data.SqlDbType,Open.Database.Extensions.SqlClient.ExpressiveSqlCommand}.Param[])": "Open.Database.Extensions.SqlClient.ExpressiveSqlCommand.yml", - "Open.Database.Extensions.SqlClient.ExpressiveSqlCommand.#ctor(Open.Database.Extensions.IDbConnectionFactory{System.Data.SqlClient.SqlConnection},System.Data.CommandType,System.String,System.Collections.Generic.List{Open.Database.Extensions.ExpressiveCommandBase{System.Data.SqlClient.SqlConnection,System.Data.SqlClient.SqlCommand,System.Data.SqlDbType,Open.Database.Extensions.SqlClient.ExpressiveSqlCommand}.Param})": "Open.Database.Extensions.SqlClient.ExpressiveSqlCommand.yml", - "Open.Database.Extensions.SqlClient.ExpressiveSqlCommand.#ctor(System.Data.SqlClient.SqlConnection,System.Data.CommandType,System.String,Open.Database.Extensions.ExpressiveCommandBase{System.Data.SqlClient.SqlConnection,System.Data.SqlClient.SqlCommand,System.Data.SqlDbType,Open.Database.Extensions.SqlClient.ExpressiveSqlCommand}.Param[])": "Open.Database.Extensions.SqlClient.ExpressiveSqlCommand.yml", - "Open.Database.Extensions.SqlClient.ExpressiveSqlCommand.#ctor(System.Data.SqlClient.SqlConnection,System.Data.CommandType,System.String,System.Collections.Generic.List{Open.Database.Extensions.ExpressiveCommandBase{System.Data.SqlClient.SqlConnection,System.Data.SqlClient.SqlCommand,System.Data.SqlDbType,Open.Database.Extensions.SqlClient.ExpressiveSqlCommand}.Param})": "Open.Database.Extensions.SqlClient.ExpressiveSqlCommand.yml", + "Open.Database.Extensions.SqlClient.ExpressiveSqlCommand.#ctor(Open.Database.Extensions.IDbConnectionFactory{System.Data.SqlClient.SqlConnection},System.Data.CommandType,System.String,System.Collections.Generic.IEnumerable{Open.Database.Extensions.ExpressiveCommandBase{System.Data.SqlClient.SqlConnection,System.Data.SqlClient.SqlCommand,System.Data.SqlDbType,Open.Database.Extensions.SqlClient.ExpressiveSqlCommand}.Param})": "Open.Database.Extensions.SqlClient.ExpressiveSqlCommand.yml", + "Open.Database.Extensions.SqlClient.ExpressiveSqlCommand.#ctor(System.Data.SqlClient.SqlConnection,System.Data.SqlClient.SqlTransaction,System.Data.CommandType,System.String,System.Collections.Generic.IEnumerable{Open.Database.Extensions.ExpressiveCommandBase{System.Data.SqlClient.SqlConnection,System.Data.SqlClient.SqlCommand,System.Data.SqlDbType,Open.Database.Extensions.SqlClient.ExpressiveSqlCommand}.Param})": "Open.Database.Extensions.SqlClient.ExpressiveSqlCommand.yml", "Open.Database.Extensions.SqlClient.ExpressiveSqlCommand.AddParams(System.Data.SqlClient.SqlCommand)": "Open.Database.Extensions.SqlClient.ExpressiveSqlCommand.yml", "Open.Database.Extensions.SqlClient.Extensions": "Open.Database.Extensions.SqlClient.Extensions.yml", "Open.Database.Extensions.SqlClient.Extensions.AddParameter(System.Data.SqlClient.SqlCommand,System.String,System.Object,System.Data.SqlDbType,System.Data.ParameterDirection)": "Open.Database.Extensions.SqlClient.Extensions.yml", @@ -292,11 +323,49 @@ "Open.Database.Extensions.SqlClient.Extensions.AddParameterType(System.Data.SqlClient.SqlCommand,System.String,System.Data.SqlDbType,System.Data.ParameterDirection)": "Open.Database.Extensions.SqlClient.Extensions.yml", "Open.Database.Extensions.SqlClient.Extensions.Command(Open.Database.Extensions.IDbConnectionFactory{System.Data.SqlClient.SqlConnection},System.String,System.Data.CommandType)": "Open.Database.Extensions.SqlClient.Extensions.yml", "Open.Database.Extensions.SqlClient.Extensions.Command(System.Data.SqlClient.SqlConnection,System.String,System.Data.CommandType)": "Open.Database.Extensions.SqlClient.Extensions.yml", + "Open.Database.Extensions.SqlClient.Extensions.Command(System.Data.SqlClient.SqlTransaction,System.String,System.Data.CommandType)": "Open.Database.Extensions.SqlClient.Extensions.yml", "Open.Database.Extensions.SqlClient.Extensions.Command(System.Func{System.Data.SqlClient.SqlConnection},System.String,System.Data.CommandType)": "Open.Database.Extensions.SqlClient.Extensions.yml", "Open.Database.Extensions.SqlClient.Extensions.CreateCommand(System.Data.SqlClient.SqlConnection,System.Data.CommandType,System.String,System.Int32)": "Open.Database.Extensions.SqlClient.Extensions.yml", + "Open.Database.Extensions.SqlClient.Extensions.CreateCommand(System.Data.SqlClient.SqlTransaction,System.Data.CommandType,System.String,System.Int32)": "Open.Database.Extensions.SqlClient.Extensions.yml", "Open.Database.Extensions.SqlClient.Extensions.CreateStoredProcedureCommand(System.Data.SqlClient.SqlConnection,System.String,System.Int32)": "Open.Database.Extensions.SqlClient.Extensions.yml", + "Open.Database.Extensions.SqlClient.Extensions.CreateStoredProcedureCommand(System.Data.SqlClient.SqlTransaction,System.String,System.Int32)": "Open.Database.Extensions.SqlClient.Extensions.yml", + "Open.Database.Extensions.SqlClient.Extensions.CreateTextCommand(System.Data.SqlClient.SqlConnection,System.String,System.Int32)": "Open.Database.Extensions.SqlClient.Extensions.yml", + "Open.Database.Extensions.SqlClient.Extensions.CreateTextCommand(System.Data.SqlClient.SqlTransaction,System.String,System.Int32)": "Open.Database.Extensions.SqlClient.Extensions.yml", + "Open.Database.Extensions.SqlClient.Extensions.ExecuteTransaction(System.Data.SqlClient.SqlConnection,System.Action{System.Data.SqlClient.SqlTransaction})": "Open.Database.Extensions.SqlClient.Extensions.yml", + "Open.Database.Extensions.SqlClient.Extensions.ExecuteTransaction(System.Data.SqlClient.SqlConnection,System.Data.IsolationLevel,System.Action{System.Data.SqlClient.SqlTransaction})": "Open.Database.Extensions.SqlClient.Extensions.yml", + "Open.Database.Extensions.SqlClient.Extensions.ExecuteTransaction(System.Data.SqlClient.SqlConnection,System.Data.IsolationLevel,System.Nullable{System.Threading.CancellationToken},System.Action{System.Data.SqlClient.SqlTransaction})": "Open.Database.Extensions.SqlClient.Extensions.yml", + "Open.Database.Extensions.SqlClient.Extensions.ExecuteTransaction(System.Data.SqlClient.SqlConnection,System.Nullable{System.Threading.CancellationToken},System.Action{System.Data.SqlClient.SqlTransaction})": "Open.Database.Extensions.SqlClient.Extensions.yml", + "Open.Database.Extensions.SqlClient.Extensions.ExecuteTransaction``1(System.Data.SqlClient.SqlConnection,System.Data.IsolationLevel,System.Func{System.Data.SqlClient.SqlTransaction,``0})": "Open.Database.Extensions.SqlClient.Extensions.yml", + "Open.Database.Extensions.SqlClient.Extensions.ExecuteTransaction``1(System.Data.SqlClient.SqlConnection,System.Data.IsolationLevel,System.Nullable{System.Threading.CancellationToken},System.Func{System.Data.SqlClient.SqlTransaction,``0})": "Open.Database.Extensions.SqlClient.Extensions.yml", + "Open.Database.Extensions.SqlClient.Extensions.ExecuteTransaction``1(System.Data.SqlClient.SqlConnection,System.Func{System.Data.SqlClient.SqlTransaction,``0})": "Open.Database.Extensions.SqlClient.Extensions.yml", + "Open.Database.Extensions.SqlClient.Extensions.ExecuteTransaction``1(System.Data.SqlClient.SqlConnection,System.Nullable{System.Threading.CancellationToken},System.Func{System.Data.SqlClient.SqlTransaction,``0})": "Open.Database.Extensions.SqlClient.Extensions.yml", + "Open.Database.Extensions.SqlClient.Extensions.ExecuteTransactionAsync(System.Data.SqlClient.SqlConnection,System.Data.IsolationLevel,System.Func{System.Data.SqlClient.SqlTransaction,System.Threading.Tasks.Task})": "Open.Database.Extensions.SqlClient.Extensions.yml", + "Open.Database.Extensions.SqlClient.Extensions.ExecuteTransactionAsync(System.Data.SqlClient.SqlConnection,System.Data.IsolationLevel,System.Nullable{System.Threading.CancellationToken},System.Func{System.Data.SqlClient.SqlTransaction,System.Threading.Tasks.Task})": "Open.Database.Extensions.SqlClient.Extensions.yml", + "Open.Database.Extensions.SqlClient.Extensions.ExecuteTransactionAsync(System.Data.SqlClient.SqlConnection,System.Func{System.Data.SqlClient.SqlTransaction,System.Threading.Tasks.Task})": "Open.Database.Extensions.SqlClient.Extensions.yml", + "Open.Database.Extensions.SqlClient.Extensions.ExecuteTransactionAsync(System.Data.SqlClient.SqlConnection,System.Nullable{System.Threading.CancellationToken},System.Func{System.Data.SqlClient.SqlTransaction,System.Threading.Tasks.Task})": "Open.Database.Extensions.SqlClient.Extensions.yml", + "Open.Database.Extensions.SqlClient.Extensions.ExecuteTransactionAsync``1(System.Data.SqlClient.SqlConnection,System.Data.IsolationLevel,System.Func{System.Data.SqlClient.SqlTransaction,System.Threading.Tasks.Task{``0}})": "Open.Database.Extensions.SqlClient.Extensions.yml", + "Open.Database.Extensions.SqlClient.Extensions.ExecuteTransactionAsync``1(System.Data.SqlClient.SqlConnection,System.Data.IsolationLevel,System.Nullable{System.Threading.CancellationToken},System.Func{System.Data.SqlClient.SqlTransaction,System.Threading.Tasks.Task{``0}})": "Open.Database.Extensions.SqlClient.Extensions.yml", + "Open.Database.Extensions.SqlClient.Extensions.ExecuteTransactionAsync``1(System.Data.SqlClient.SqlConnection,System.Func{System.Data.SqlClient.SqlTransaction,System.Threading.Tasks.Task{``0}})": "Open.Database.Extensions.SqlClient.Extensions.yml", + "Open.Database.Extensions.SqlClient.Extensions.ExecuteTransactionAsync``1(System.Data.SqlClient.SqlConnection,System.Nullable{System.Threading.CancellationToken},System.Func{System.Data.SqlClient.SqlTransaction,System.Threading.Tasks.Task{``0}})": "Open.Database.Extensions.SqlClient.Extensions.yml", + "Open.Database.Extensions.SqlClient.Extensions.ExecuteTransactionConditional(System.Data.SqlClient.SqlConnection,System.Data.IsolationLevel,System.Func{System.Data.SqlClient.SqlTransaction,System.Boolean})": "Open.Database.Extensions.SqlClient.Extensions.yml", + "Open.Database.Extensions.SqlClient.Extensions.ExecuteTransactionConditional(System.Data.SqlClient.SqlConnection,System.Data.IsolationLevel,System.Nullable{System.Threading.CancellationToken},System.Func{System.Data.SqlClient.SqlTransaction,System.Boolean})": "Open.Database.Extensions.SqlClient.Extensions.yml", + "Open.Database.Extensions.SqlClient.Extensions.ExecuteTransactionConditional(System.Data.SqlClient.SqlConnection,System.Func{System.Data.SqlClient.SqlTransaction,System.Boolean})": "Open.Database.Extensions.SqlClient.Extensions.yml", + "Open.Database.Extensions.SqlClient.Extensions.ExecuteTransactionConditional(System.Data.SqlClient.SqlConnection,System.Nullable{System.Threading.CancellationToken},System.Func{System.Data.SqlClient.SqlTransaction,System.Boolean})": "Open.Database.Extensions.SqlClient.Extensions.yml", + "Open.Database.Extensions.SqlClient.Extensions.ExecuteTransactionConditional``1(System.Data.SqlClient.SqlConnection,System.Data.IsolationLevel,System.Func{System.Data.SqlClient.SqlTransaction,System.ValueTuple{System.Boolean,``0}})": "Open.Database.Extensions.SqlClient.Extensions.yml", + "Open.Database.Extensions.SqlClient.Extensions.ExecuteTransactionConditional``1(System.Data.SqlClient.SqlConnection,System.Data.IsolationLevel,System.Nullable{System.Threading.CancellationToken},System.Func{System.Data.SqlClient.SqlTransaction,System.ValueTuple{System.Boolean,``0}})": "Open.Database.Extensions.SqlClient.Extensions.yml", + "Open.Database.Extensions.SqlClient.Extensions.ExecuteTransactionConditional``1(System.Data.SqlClient.SqlConnection,System.Func{System.Data.SqlClient.SqlTransaction,System.ValueTuple{System.Boolean,``0}})": "Open.Database.Extensions.SqlClient.Extensions.yml", + "Open.Database.Extensions.SqlClient.Extensions.ExecuteTransactionConditional``1(System.Data.SqlClient.SqlConnection,System.Nullable{System.Threading.CancellationToken},System.Func{System.Data.SqlClient.SqlTransaction,System.ValueTuple{System.Boolean,``0}})": "Open.Database.Extensions.SqlClient.Extensions.yml", + "Open.Database.Extensions.SqlClient.Extensions.ExecuteTransactionConditionalAsync(System.Data.SqlClient.SqlConnection,System.Data.IsolationLevel,System.Func{System.Data.SqlClient.SqlTransaction,System.Threading.Tasks.Task{System.Boolean}})": "Open.Database.Extensions.SqlClient.Extensions.yml", + "Open.Database.Extensions.SqlClient.Extensions.ExecuteTransactionConditionalAsync(System.Data.SqlClient.SqlConnection,System.Data.IsolationLevel,System.Nullable{System.Threading.CancellationToken},System.Func{System.Data.SqlClient.SqlTransaction,System.Threading.Tasks.Task{System.Boolean}})": "Open.Database.Extensions.SqlClient.Extensions.yml", + "Open.Database.Extensions.SqlClient.Extensions.ExecuteTransactionConditionalAsync(System.Data.SqlClient.SqlConnection,System.Func{System.Data.SqlClient.SqlTransaction,System.Threading.Tasks.Task{System.Boolean}})": "Open.Database.Extensions.SqlClient.Extensions.yml", + "Open.Database.Extensions.SqlClient.Extensions.ExecuteTransactionConditionalAsync(System.Data.SqlClient.SqlConnection,System.Nullable{System.Threading.CancellationToken},System.Func{System.Data.SqlClient.SqlTransaction,System.Threading.Tasks.Task{System.Boolean}})": "Open.Database.Extensions.SqlClient.Extensions.yml", + "Open.Database.Extensions.SqlClient.Extensions.ExecuteTransactionConditionalAsync``1(System.Data.SqlClient.SqlConnection,System.Data.IsolationLevel,System.Func{System.Data.SqlClient.SqlTransaction,System.Threading.Tasks.Task{System.ValueTuple{System.Boolean,``0}}})": "Open.Database.Extensions.SqlClient.Extensions.yml", + "Open.Database.Extensions.SqlClient.Extensions.ExecuteTransactionConditionalAsync``1(System.Data.SqlClient.SqlConnection,System.Data.IsolationLevel,System.Nullable{System.Threading.CancellationToken},System.Func{System.Data.SqlClient.SqlTransaction,System.Threading.Tasks.Task{System.ValueTuple{System.Boolean,``0}}})": "Open.Database.Extensions.SqlClient.Extensions.yml", + "Open.Database.Extensions.SqlClient.Extensions.ExecuteTransactionConditionalAsync``1(System.Data.SqlClient.SqlConnection,System.Func{System.Data.SqlClient.SqlTransaction,System.Threading.Tasks.Task{System.ValueTuple{System.Boolean,``0}}})": "Open.Database.Extensions.SqlClient.Extensions.yml", + "Open.Database.Extensions.SqlClient.Extensions.ExecuteTransactionConditionalAsync``1(System.Data.SqlClient.SqlConnection,System.Nullable{System.Threading.CancellationToken},System.Func{System.Data.SqlClient.SqlTransaction,System.Threading.Tasks.Task{System.ValueTuple{System.Boolean,``0}}})": "Open.Database.Extensions.SqlClient.Extensions.yml", "Open.Database.Extensions.SqlClient.Extensions.StoredProcedure(Open.Database.Extensions.IDbConnectionFactory{System.Data.SqlClient.SqlConnection},System.String)": "Open.Database.Extensions.SqlClient.Extensions.yml", "Open.Database.Extensions.SqlClient.Extensions.StoredProcedure(System.Data.SqlClient.SqlConnection,System.String)": "Open.Database.Extensions.SqlClient.Extensions.yml", + "Open.Database.Extensions.SqlClient.Extensions.StoredProcedure(System.Data.SqlClient.SqlTransaction,System.String)": "Open.Database.Extensions.SqlClient.Extensions.yml", "Open.Database.Extensions.SqlClient.Extensions.StoredProcedure(System.Func{System.Data.SqlClient.SqlConnection},System.String)": "Open.Database.Extensions.SqlClient.Extensions.yml", "Open.Database.Extensions.SqlClient.SqlConnectionFactory": "Open.Database.Extensions.SqlClient.SqlConnectionFactory.yml", "Open.Database.Extensions.SqlClient.SqlConnectionFactory.#ctor(System.Func{System.Data.SqlClient.SqlConnection})": "Open.Database.Extensions.SqlClient.SqlConnectionFactory.yml", diff --git a/docs/Documentation.xml b/docs/Documentation.xml index 30cdc00..8061622 100644 --- a/docs/Documentation.xml +++ b/docs/Documentation.xml @@ -52,14 +52,20 @@ The connection to execute commands on if not using a connection factory. - + + + The transaction to execute commands on if not using a connection factory. + + + The factory to generate connections from. The command type>. The SQL command. The list of params - + The connection to execute the command on. + The optional transaction to execute the command on. The command type>. The SQL command. The list of params @@ -184,13 +190,13 @@ The command to add parameters to. - + Handles providing the connection for use with the command. The handler for use with the connection. - + Handles providing the connection for use with the command. @@ -557,26 +563,15 @@ An abstraction for executing commands on a database using best practices and simplified expressive syntax. - - The factory to generate connections from. - The command type>. - The SQL command. - The list of params - - + The factory to generate connections from. The command type>. The SQL command. The list of params - - The connection to execute the command on. - The command type>. - The SQL command. - The list of params - - + The connection to execute the command on. + The optional transaction to execute the command on. The command type>. The SQL command. The list of params @@ -597,14 +592,15 @@ The DB type enum to use for parameters. The type of this class in order to facilitate proper expressive notation. - + The factory to generate connections from. The command type>. The SQL command. The list of params - + The connection to execute the command on. + The optional transaction to execute the command on. The command type>. The SQL command. The list of params @@ -710,6 +706,7 @@ Iterates asynchronously until the handler returns false. Then cancels. If true, the iteration continues. + An optional cancellation token. The task that completes when the iteration is done or the predicate evaluates false. @@ -946,6 +943,15 @@ The command type. The resultant ExpressiveDbCommand. + + + Creates an ExpressiveDbCommand for subsequent configuration and execution. + + The transaction to execute the command on. + The command text or stored procedure name to use. + The command type. + The resultant ExpressiveDbCommand. + Creates an ExpressiveDbCommand with command type set to StoredProcedure for subsequent configuration and execution. @@ -954,6 +960,14 @@ The command text or stored procedure name to use. The resultant ExpressiveDbCommand. + + + Creates an ExpressiveDbCommand with command type set to StoredProcedure for subsequent configuration and execution. + + The transaction to execute the command on. + The command text or stored procedure name to use. + The resultant ExpressiveDbCommand. + Creates an ExpressiveDbCommand for subsequent configuration and execution. @@ -988,81 +1002,155 @@ The command text or stored procedure name to use. The resultant ExpressiveDbCommand. - + - Any DBNull values are converted to null. + Shortcut for creating an IDbCommand from any IDbConnection. - The source values. - The converted enumerable. + The connection to create a command from. + The command type. Text, StoredProcedure, or TableDirect. + The command text or stored procedure name to use. + The number of seconds to wait before the command times out. + The created SqlCommand. - + - Returns a copy of this array with any DBNull values converted to null. + Shortcut for creating a text IDbCommand from any IDbConnection. - The source values. - A new array containing the results with. + The connection to create a command from. + The command text or stored procedure name to use. + The number of seconds to wait before the command times out. + The created SqlCommand. - + - Replaces any DBNull values in the array with null; + Shortcut for creating an IDbCommand from any IDbConnection. - The source values. - The converted enumerable. + The connection to create a command from. + The command text or stored procedure name to use. + The number of seconds to wait before the command times out. + The created SqlCommand. - + - If the connection isn't open, opens the connection. - If the connection is in neither open or close, first closes the connection. + Shortcut for creating an DbCommand from any DbConnection. - The prior connection state. + The connection to create a command from. + The command type. Text, StoredProcedure, or TableDirect. + The command text or stored procedure name to use. + The number of seconds to wait before the command times out. + The created SqlCommand. - + - If the connection isn't open, opens the connection. - If the connection is in neither open or close, first closes the connection. + Shortcut for creating a text DbCommand from any DbConnection. - The connection to transact with. - An optional token to cancel opening. - A task containing the prior connection state. + The connection to create a command from. + The command text or stored procedure name to use. + The number of seconds to wait before the command times out. + The created SqlCommand. - + - Shortcut for creating an IDbCommand from any IDbConnection. + Shortcut for creating a stored procedure DbCommand from any DbConnection. The connection to create a command from. + The command text or stored procedure name to use. + The number of seconds to wait before the command times out. + The created SqlCommand. + + + + Shortcut for creating an IDbCommand from any IDbTransaction. + + The transaction to create a command from. The command type. Text, StoredProcedure, or TableDirect. The command text or stored procedure name to use. The number of seconds to wait before the command times out. The created SqlCommand. - + - Shortcut for creating an IDbCommand from any IDbConnection. + Shortcut for creating a text IDbCommand from any IDbTransaction. - The connection to create a command from. + The transaction to create a command from. The command text or stored procedure name to use. The number of seconds to wait before the command times out. The created SqlCommand. - + - Shortcut for creating an DbCommand from any DbConnection. + Shortcut for creating a stored procedure IDbCommand from any IDbTransaction. - The connection to create a command from. + The transaction to create a command from. + The command text or stored procedure name to use. + The number of seconds to wait before the command times out. + The created SqlCommand. + + + + Shortcut for creating an DbCommand from any DbTransaction. + + The transaction to create a command from. The command type. Text, StoredProcedure, or TableDirect. The command text or stored procedure name to use. The number of seconds to wait before the command times out. The created SqlCommand. - + - Shortcut for creating an DbCommand from any DbConnection. + Shortcut for creating a text DbCommand from any DbTransaction. - The connection to create a command from. + The transaction to create a command from. The command text or stored procedure name to use. The number of seconds to wait before the command times out. The created SqlCommand. + + + Shortcut for creating a stored procedure DbCommand from any DbTransaction. + + The transaction to create a command from. + The command text or stored procedure name to use. + The number of seconds to wait before the command times out. + The created SqlCommand. + + + + Any DBNull values are converted to null. + + The source values. + The converted enumerable. + + + + Returns a copy of this array with any DBNull values converted to null. + + The source values. + A new array containing the results with. + + + + Replaces any DBNull values in the array with null; + + The source values. + The converted enumerable. + + + + If the connection isn't open, opens the connection. + If the connection is in neither open or close, first closes the connection. + + The prior connection state. + + + + If the connection isn't open, opens the connection. + If the connection is in neither open or close, first closes the connection. + + The connection to transact with. + An optional token to cancel opening. + A task containing the prior connection state. + Shortcut for adding command parameter. @@ -2063,169 +2151,382 @@ The remaining column names to request from the reader for each record. The QueryResult that contains all the results and the column mappings. - + - Begins a transaction before executing the action. Commits if there are no exceptions and 'Commit' value from the action is true. Otherwise rolls-back the transaction. + Begins a transaction before executing the action. Commits if there are no exceptions, the 'Commit' value from the action is true and the optional cancellation token has not been cancelled. Otherwise rolls-back the transaction. - The connection type. The value returned from the action. The connection to transact with. - The handler to execute while a transaction is pending. Returning a 'Commit' value of true signals to commit the transaction. + The isolation level for the transaction. A optional token that if cancelled will cause this transaction to be aborted or rolled-back. + The handler to execute while a transaction is pending. Returning a 'Commit' value of true signals to commit the transaction. The value retured from the conditional action. - + - Begins a transaction before executing the action. Commits if there are no exceptions and the conditional actio returns true. Otherwise rolls-back the transaction. + Begins a transaction before executing the action. Commits if there are no exceptions, the conditional action returns true, and the optional cancellation token is not cancelled. Otherwise rolls-back the transaction. - The connection type. The connection to transact with. - The handler to execute while a transaction is pending. Returning true signals to commit the transaction. + The isolation level for the transaction. A optional token that if cancelled will cause this transaction to be aborted or rolled-back. + The handler to execute while a transaction is pending. Returning true signals to commit the transaction. True if committed. - + Begins a transaction before executing the action. Commits if there are no exceptions and the optional provided token is not cancelled. Otherwise rolls-back the transaction. - The connection type. The value returned from the action. The connection to transact with. - The handler to execute while a transaction is pending. + The isolation level for the transaction. A optional token that if cancelled will cause this transaction to be aborted or rolled-back. + The handler to execute while a transaction is pending. The value of the action. - + Begins a transaction before executing the action. Commits if there are no exceptions and the optional provided token is not cancelled. Otherwise rolls-back the transaction. - The connection type. The connection to transact with. - The handler to execute while a transaction is pending. + The isolation level for the transaction. A optional token that if cancelled will cause this transaction to be aborted or rolled-back. + The handler to execute while a transaction is pending. - + Begins a transaction before executing the action. Commits if there are no exceptions, the 'Commit' value from the action is true, and the optional provided token is not cancelled. Otherwise rolls-back the transaction. - The connection type. The value returned from the action. The connection to transact with. - The handler to execute while a transaction is pending. Returning a 'Commit' value of true signals to commit the transaction. + The isolation level for the transaction. A optional token that if cancelled will cause this transaction to be aborted or rolled-back. + The handler to execute while a transaction is pending. Returning a 'Commit' value of true signals to commit the transaction. The value of the awaited action. - + Begins a transaction before executing the action. Commits if there are no exceptions, the 'Commit' value from the action is true, and the optional provided token is not cancelled. Otherwise rolls-back the transaction. - The connection type. - The value returned from the action. The connection to transact with. - The handler to execute while a transaction is pending. Returning true signals to commit the transaction. + The isolation level for the transaction. A optional token that if cancelled will cause this transaction to be aborted or rolled-back. + The handler to execute while a transaction is pending. Returning true signals to commit the transaction. The value of the awaited action. - + Begins a transaction before executing the action. Commits if there are no exceptions and the optional provided token is not cancelled. Otherwise rolls-back the transaction. - The connection type. The value returned from the action. The connection to transact with. - The handler to execute while a transaction is pending. + The isolation level for the transaction. A optional token that if cancelled will cause this transaction to be aborted or rolled-back. + The handler to execute while a transaction is pending. The value of the awaited action. - + Begins a transaction before executing the action. Commits if there are no exceptions and the optional provided token is not cancelled. Otherwise rolls-back the transaction. - The connection type. The connection to transact with. - The handler to execute while a transaction is pending. + The isolation level for the transaction. A optional token that if cancelled will cause this transaction to be aborted or rolled-back. + The handler to execute while a transaction is pending. - + - Simplified interface with IDbConnection as the generic type. + Begins a transaction before executing the action. Commits if there are no exceptions and 'Commit' value from the action is true. Otherwise rolls-back the transaction. + The value returned from the action. + The connection to transact with. + The isolation level for the transaction. + The handler to execute while a transaction is pending. Returning a 'Commit' value of true signals to commit the transaction. + The value retured from the conditional action. - + - Generates a new connection of declared generic type. + Begins a transaction before executing the action. Commits if there are no exceptions and the conditional action returns true. Otherwise rolls-back the transaction. - + The connection to transact with. + The isolation level for the transaction. + The handler to execute while a transaction is pending. Returning true signals to commit the transaction. + True if committed. - + - Base interface for creating connections. - Useful for dependency injection. + Begins a transaction before executing the action. Commits if there are no exceptions. Otherwise rolls-back the transaction. - The actual connection type. + The value returned from the action. + The connection to transact with. + The isolation level for the transaction. + The handler to execute while a transaction is pending. + The value of the action. - + - Generates a new connection of declared generic type. + Begins a transaction before executing the action. Commits if there are no exceptions. Otherwise rolls-back the transaction. - + The connection to transact with. + The isolation level for the transaction. + The handler to execute while a transaction is pending. - + - A container for data reader results that also provides the column names and other helpful data methods. + Begins a transaction before executing the action. Commits if there are no exceptions and the 'Commit' value from the action is true. Otherwise rolls-back the transaction. - The type of the result property. - - - The ordinal values requested - The column names requested. - The result. + The value returned from the action. + The connection to transact with. + The isolation level for the transaction. + The handler to execute while a transaction is pending. Returning a 'Commit' value of true signals to commit the transaction. + The value of the awaited action. - + - The number of columns. + Begins a transaction before executing the action. Commits if there are no exceptions and the value from the action is true. Otherwise rolls-back the transaction. + The connection to transact with. + The isolation level for the transaction. + The handler to execute while a transaction is pending. Returning true signals to commit the transaction. + The value of the awaited action. - + - The ordinal values requested. + Begins a transaction before executing the action. Commits if there are no exceptions. Otherwise rolls-back the transaction. + The value returned from the action. + The connection to transact with. + The isolation level for the transaction. + The handler to execute while a transaction is pending. + The value of the awaited action. - + - The column names requested. + Begins a transaction before executing the action. Commits if there are no exceptions. Otherwise rolls-back the transaction. + The connection to transact with. + The isolation level for the transaction. + The handler to execute while a transaction is pending. - + - The values requested. A Queue is used since values are typically used first in first out and dequeuing results helps reduced redunant memory usage. + Begins a transaction before executing the action. Commits if there are no exceptions, the 'Commit' value from the action is true and the optional cancellation token has not been cancelled. Otherwise rolls-back the transaction. + The value returned from the action. + The connection to transact with. + A optional token that if cancelled will cause this transaction to be aborted or rolled-back. + The handler to execute while a transaction is pending. Returning a 'Commit' value of true signals to commit the transaction. + The value retured from the conditional action. - + - A set of extensions for getting column data from a QueryResult. + Begins a transaction before executing the action. Commits if there are no exceptions, the conditional action returns true, and the optional cancellation token is not cancelled. Otherwise rolls-back the transaction. + The connection to transact with. + A optional token that if cancelled will cause this transaction to be aborted or rolled-back. + The handler to execute while a transaction is pending. Returning true signals to commit the transaction. + True if committed. - + - Returns an enumerable that dequeues the results and returns a column mapped dictionary for each entry. - DBNull values are converted to null. + Begins a transaction before executing the action. Commits if there are no exceptions and the optional provided token is not cancelled. Otherwise rolls-back the transaction. - The query result. Typically produced by a .Retrieve method. - An enumerable that dequeues the results and returns a column mapped dictionary for each entry + The value returned from the action. + The connection to transact with. + A optional token that if cancelled will cause this transaction to be aborted or rolled-back. + The handler to execute while a transaction is pending. + The value of the action. - + - Returns an enumerable that dequeues the results and returns a column mapped dictionary for each entry. - DBNull values are converted to null. + Begins a transaction before executing the action. Commits if there are no exceptions and the optional provided token is not cancelled. Otherwise rolls-back the transaction. - The query result. Typically produced by a .Retrieve method. - An enumerable that dequeues the results and returns a column mapped dictionary for each entry + The connection to transact with. + A optional token that if cancelled will cause this transaction to be aborted or rolled-back. + The handler to execute while a transaction is pending. - + - Returns an enumerable that dequeues the results and attempts to map the fields to type T. - DBNull values are converted to null. + Begins a transaction before executing the action. Commits if there are no exceptions, the 'Commit' value from the action is true, and the optional provided token is not cancelled. Otherwise rolls-back the transaction. + + The value returned from the action. + The connection to transact with. + A optional token that if cancelled will cause this transaction to be aborted or rolled-back. + The handler to execute while a transaction is pending. Returning a 'Commit' value of true signals to commit the transaction. + The value of the awaited action. + + + + Begins a transaction before executing the action. Commits if there are no exceptions, the value from the action is true, and the optional provided token is not cancelled. Otherwise rolls-back the transaction. + + The connection to transact with. + A optional token that if cancelled will cause this transaction to be aborted or rolled-back. + The handler to execute while a transaction is pending. Returning true signals to commit the transaction. + The value of the awaited action. + + + + Begins a transaction before executing the action. Commits if there are no exceptions and the optional provided token is not cancelled. Otherwise rolls-back the transaction. + + The value returned from the action. + The connection to transact with. + A optional token that if cancelled will cause this transaction to be aborted or rolled-back. + The handler to execute while a transaction is pending. + The value of the awaited action. + + + + Begins a transaction before executing the action. Commits if there are no exceptions and the optional provided token is not cancelled. Otherwise rolls-back the transaction. + + The connection to transact with. + A optional token that if cancelled will cause this transaction to be aborted or rolled-back. + The handler to execute while a transaction is pending. + + + + Begins a transaction before executing the action. Commits if there are no exceptions and 'Commit' value from the action is true. Otherwise rolls-back the transaction. + + The value returned from the action. + The connection to transact with. + The handler to execute while a transaction is pending. Returning a 'Commit' value of true signals to commit the transaction. + The value retured from the conditional action. + + + + Begins a transaction before executing the action. Commits if there are no exceptions and the conditional action returns true. Otherwise rolls-back the transaction. + + The connection to transact with. + The handler to execute while a transaction is pending. Returning true signals to commit the transaction. + True if committed. + + + + Begins a transaction before executing the action. Commits if there are no exceptions. Otherwise rolls-back the transaction. + + The value returned from the action. + The connection to transact with. + The handler to execute while a transaction is pending. + The value of the action. + + + + Begins a transaction before executing the action. Commits if there are no exceptions. Otherwise rolls-back the transaction. + + The connection to transact with. + The handler to execute while a transaction is pending. + + + + Begins a transaction before executing the action. Commits if there are no exceptions and the 'Commit' value from the action is true. Otherwise rolls-back the transaction. + + The value returned from the action. + The connection to transact with. + The handler to execute while a transaction is pending. Returning a 'Commit' value of true signals to commit the transaction. + The value of the awaited action. + + + + Begins a transaction before executing the action. Commits if there are no exceptions and the value from the action is true. Otherwise rolls-back the transaction. + + The connection to transact with. + The handler to execute while a transaction is pending. Returning true signals to commit the transaction. + The value of the awaited action. + + + + Begins a transaction before executing the action. Commits if there are no exceptions. Otherwise rolls-back the transaction. + + The value returned from the action. + The connection to transact with. + The handler to execute while a transaction is pending. + The value of the awaited action. + + + + Begins a transaction before executing the action. Commits if there are no exceptions. Otherwise rolls-back the transaction. + + The connection to transact with. + The handler to execute while a transaction is pending. + + + + Simplified interface with IDbConnection as the generic type. + + + + + Generates a new connection of declared generic type. + + + + + + Base interface for creating connections. + Useful for dependency injection. + + The actual connection type. + + + + Generates a new connection of declared generic type. + + + + + + A container for data reader results that also provides the column names and other helpful data methods. + + The type of the result property. + + + The ordinal values requested + The column names requested. + The result. + + + + The number of columns. + + + + + The ordinal values requested. + + + + + The column names requested. + + + + + The values requested. A Queue is used since values are typically used first in first out and dequeuing results helps reduced redunant memory usage. + + + + + A set of extensions for getting column data from a QueryResult. + + + + + Returns an enumerable that dequeues the results and returns a column mapped dictionary for each entry. + DBNull values are converted to null. + + The query result. Typically produced by a .Retrieve method. + An enumerable that dequeues the results and returns a column mapped dictionary for each entry + + + + Returns an enumerable that dequeues the results and returns a column mapped dictionary for each entry. + DBNull values are converted to null. + + The query result. Typically produced by a .Retrieve method. + An enumerable that dequeues the results and returns a column mapped dictionary for each entry + + + + Returns an enumerable that dequeues the results and attempts to map the fields to type T. + DBNull values are converted to null. The query result. Typically produced by a .Retrieve method. An optional override map of field names to column names where the keys are the property names, and values are the column names. @@ -2314,26 +2615,15 @@ A specialized for SqlClient abstraction for executing commands on a database using best practices and simplified expressive syntax. - + The factory to generate connections from. The command type>. The SQL command. The list of params - - The factory to generate connections from. - The command type>. - The SQL command. - The list of params - - - The connection to execute the command on. - The command type>. - The SQL command. - The list of params - - + The connection to execute the command on. + The optional transaction to execute the command on. The command type>. The SQL command. The list of params @@ -2359,15 +2649,52 @@ The number of seconds to wait before the command times out. The created SqlCommand. + + + Shortcut for creating an text SqlCommand from any SqlConnection. + + The connection to create a command from. + The command text or stored procedure name to use. + The number of seconds to wait before the command times out. + The created SqlCommand. + - Shortcut for creating an SqlCommand from any SqlConnection. + Shortcut for creating a stored procedure SqlCommand from any SqlConnection. The connection to create a command from. + The command text or stored procedure name to use. + The number of seconds to wait before the command times out. + The created SqlCommand. + + + + Shortcut for creating an SqlCommand from any SqlTransaction. + + The transaction to create a command from. + The command type. Text, StoredProcedure, or TableDirect. The command text or stored procedure name to use. The number of seconds to wait before the command times out. The created SqlCommand. + + + Shortcut for creating a text SqlCommand from any SqlTransaction. + + The transaction to create a command from. + The command text or stored procedure name to use. + The number of seconds to wait before the command times out. + The created SqlCommand. + + + + Shortcut for creating a stored procedure SqlCommand from any SqlTransaction. + + The transaction to create a command from. + The command text or stored procedure name to use. + The number of seconds to wait before the command times out. + The created SqlCommand. + Shortcut for adding command parameter. @@ -2407,6 +2734,15 @@ The command type. The resultant ExpressiveSqlCommand. + + + Creates an ExpressiveSqlCommand for subsequent configuration and execution. + + The transaction to execute the command on. + The command text or stored procedure name to use. + The command type. + The resultant ExpressiveSqlCommand. + Creates an ExpressiveSqlCommand with command type set to StoredProcedure for subsequent configuration and execution. @@ -2415,6 +2751,14 @@ The command text or stored procedure name to use. The resultant ExpressiveSqlCommand. + + + Creates an ExpressiveSqlCommand with command type set to StoredProcedure for subsequent configuration and execution. + + The transaction to execute the command on. + The command text or stored procedure name to use. + The resultant ExpressiveSqlCommand. + Creates an ExpressiveSqlCommand for subsequent configuration and execution. @@ -2449,6 +2793,302 @@ The command text or stored procedure name to use. The resultant ExpressiveSqlCommand. + + + Begins a transaction before executing the action. Commits if there are no exceptions, the 'Commit' value from the action is true and the optional cancellation token has not been cancelled. Otherwise rolls-back the transaction. + + The value returned from the action. + The connection to transact with. + The isolation level for the transaction. + A optional token that if cancelled will cause this transaction to be aborted or rolled-back. + The handler to execute while a transaction is pending. Returning a 'Commit' value of true signals to commit the transaction. + The value retured from the conditional action. + + + + Begins a transaction before executing the action. Commits if there are no exceptions, the conditional action returns true, and the optional cancellation token is not cancelled. Otherwise rolls-back the transaction. + + The connection to transact with. + The isolation level for the transaction. + A optional token that if cancelled will cause this transaction to be aborted or rolled-back. + The handler to execute while a transaction is pending. Returning true signals to commit the transaction. + True if committed. + + + + Begins a transaction before executing the action. Commits if there are no exceptions and the optional provided token is not cancelled. Otherwise rolls-back the transaction. + + The value returned from the action. + The connection to transact with. + The isolation level for the transaction. + A optional token that if cancelled will cause this transaction to be aborted or rolled-back. + The handler to execute while a transaction is pending. + The value of the action. + + + + Begins a transaction before executing the action. Commits if there are no exceptions and the optional provided token is not cancelled. Otherwise rolls-back the transaction. + + The connection to transact with. + The isolation level for the transaction. + A optional token that if cancelled will cause this transaction to be aborted or rolled-back. + The handler to execute while a transaction is pending. + + + + Begins a transaction before executing the action. Commits if there are no exceptions, the 'Commit' value from the action is true, and the optional provided token is not cancelled. Otherwise rolls-back the transaction. + + The value returned from the action. + The connection to transact with. + The isolation level for the transaction. + A optional token that if cancelled will cause this transaction to be aborted or rolled-back. + The handler to execute while a transaction is pending. Returning a 'Commit' value of true signals to commit the transaction. + The value of the awaited action. + + + + Begins a transaction before executing the action. Commits if there are no exceptions, the 'Commit' value from the action is true, and the optional provided token is not cancelled. Otherwise rolls-back the transaction. + + The connection to transact with. + The isolation level for the transaction. + A optional token that if cancelled will cause this transaction to be aborted or rolled-back. + The handler to execute while a transaction is pending. Returning true signals to commit the transaction. + The value of the awaited action. + + + + Begins a transaction before executing the action. Commits if there are no exceptions and the optional provided token is not cancelled. Otherwise rolls-back the transaction. + + The value returned from the action. + The connection to transact with. + The isolation level for the transaction. + A optional token that if cancelled will cause this transaction to be aborted or rolled-back. + The handler to execute while a transaction is pending. + The value of the awaited action. + + + + Begins a transaction before executing the action. Commits if there are no exceptions and the optional provided token is not cancelled. Otherwise rolls-back the transaction. + + The connection to transact with. + The isolation level for the transaction. + A optional token that if cancelled will cause this transaction to be aborted or rolled-back. + The handler to execute while a transaction is pending. + + + + Begins a transaction before executing the action. Commits if there are no exceptions and 'Commit' value from the action is true. Otherwise rolls-back the transaction. + + The value returned from the action. + The connection to transact with. + The isolation level for the transaction. + The handler to execute while a transaction is pending. Returning a 'Commit' value of true signals to commit the transaction. + The value retured from the conditional action. + + + + Begins a transaction before executing the action. Commits if there are no exceptions and the conditional action returns true. Otherwise rolls-back the transaction. + + The connection to transact with. + The isolation level for the transaction. + The handler to execute while a transaction is pending. Returning true signals to commit the transaction. + True if committed. + + + + Begins a transaction before executing the action. Commits if there are no exceptions. Otherwise rolls-back the transaction. + + The value returned from the action. + The connection to transact with. + The isolation level for the transaction. + The handler to execute while a transaction is pending. + The value of the action. + + + + Begins a transaction before executing the action. Commits if there are no exceptions. Otherwise rolls-back the transaction. + + The connection to transact with. + The isolation level for the transaction. + The handler to execute while a transaction is pending. + + + + Begins a transaction before executing the action. Commits if there are no exceptions and the 'Commit' value from the action is true. Otherwise rolls-back the transaction. + + The value returned from the action. + The connection to transact with. + The isolation level for the transaction. + The handler to execute while a transaction is pending. Returning a 'Commit' value of true signals to commit the transaction. + The value of the awaited action. + + + + Begins a transaction before executing the action. Commits if there are no exceptions and the value from the action is true. Otherwise rolls-back the transaction. + + The connection to transact with. + The isolation level for the transaction. + The handler to execute while a transaction is pending. Returning true signals to commit the transaction. + The value of the awaited action. + + + + Begins a transaction before executing the action. Commits if there are no exceptions. Otherwise rolls-back the transaction. + + The value returned from the action. + The connection to transact with. + The isolation level for the transaction. + The handler to execute while a transaction is pending. + The value of the awaited action. + + + + Begins a transaction before executing the action. Commits if there are no exceptions. Otherwise rolls-back the transaction. + + The connection to transact with. + The isolation level for the transaction. + The handler to execute while a transaction is pending. + + + + Begins a transaction before executing the action. Commits if there are no exceptions, the 'Commit' value from the action is true and the optional cancellation token has not been cancelled. Otherwise rolls-back the transaction. + + The value returned from the action. + The connection to transact with. + A optional token that if cancelled will cause this transaction to be aborted or rolled-back. + The handler to execute while a transaction is pending. Returning a 'Commit' value of true signals to commit the transaction. + The value retured from the conditional action. + + + + Begins a transaction before executing the action. Commits if there are no exceptions, the conditional action returns true, and the optional cancellation token is not cancelled. Otherwise rolls-back the transaction. + + The connection to transact with. + A optional token that if cancelled will cause this transaction to be aborted or rolled-back. + The handler to execute while a transaction is pending. Returning true signals to commit the transaction. + True if committed. + + + + Begins a transaction before executing the action. Commits if there are no exceptions and the optional provided token is not cancelled. Otherwise rolls-back the transaction. + + The value returned from the action. + The connection to transact with. + A optional token that if cancelled will cause this transaction to be aborted or rolled-back. + The handler to execute while a transaction is pending. + The value of the action. + + + + Begins a transaction before executing the action. Commits if there are no exceptions and the optional provided token is not cancelled. Otherwise rolls-back the transaction. + + The connection to transact with. + A optional token that if cancelled will cause this transaction to be aborted or rolled-back. + The handler to execute while a transaction is pending. + + + + Begins a transaction before executing the action. Commits if there are no exceptions, the 'Commit' value from the action is true, and the optional provided token is not cancelled. Otherwise rolls-back the transaction. + + The value returned from the action. + The connection to transact with. + A optional token that if cancelled will cause this transaction to be aborted or rolled-back. + The handler to execute while a transaction is pending. Returning a 'Commit' value of true signals to commit the transaction. + The value of the awaited action. + + + + Begins a transaction before executing the action. Commits if there are no exceptions, the value from the action is true, and the optional provided token is not cancelled. Otherwise rolls-back the transaction. + + The connection to transact with. + A optional token that if cancelled will cause this transaction to be aborted or rolled-back. + The handler to execute while a transaction is pending. Returning true signals to commit the transaction. + The value of the awaited action. + + + + Begins a transaction before executing the action. Commits if there are no exceptions and the optional provided token is not cancelled. Otherwise rolls-back the transaction. + + The value returned from the action. + The connection to transact with. + A optional token that if cancelled will cause this transaction to be aborted or rolled-back. + The handler to execute while a transaction is pending. + The value of the awaited action. + + + + Begins a transaction before executing the action. Commits if there are no exceptions and the optional provided token is not cancelled. Otherwise rolls-back the transaction. + + The connection to transact with. + A optional token that if cancelled will cause this transaction to be aborted or rolled-back. + The handler to execute while a transaction is pending. + + + + Begins a transaction before executing the action. Commits if there are no exceptions and 'Commit' value from the action is true. Otherwise rolls-back the transaction. + + The value returned from the action. + The connection to transact with. + The handler to execute while a transaction is pending. Returning a 'Commit' value of true signals to commit the transaction. + The value retured from the conditional action. + + + + Begins a transaction before executing the action. Commits if there are no exceptions and the conditional action returns true. Otherwise rolls-back the transaction. + + The connection to transact with. + The handler to execute while a transaction is pending. Returning true signals to commit the transaction. + True if committed. + + + + Begins a transaction before executing the action. Commits if there are no exceptions. Otherwise rolls-back the transaction. + + The value returned from the action. + The connection to transact with. + The handler to execute while a transaction is pending. + The value of the action. + + + + Begins a transaction before executing the action. Commits if there are no exceptions. Otherwise rolls-back the transaction. + + The connection to transact with. + The handler to execute while a transaction is pending. + + + + Begins a transaction before executing the action. Commits if there are no exceptions and the 'Commit' value from the action is true. Otherwise rolls-back the transaction. + + The value returned from the action. + The connection to transact with. + The handler to execute while a transaction is pending. Returning a 'Commit' value of true signals to commit the transaction. + The value of the awaited action. + + + + Begins a transaction before executing the action. Commits if there are no exceptions and the value from the action is true. Otherwise rolls-back the transaction. + + The connection to transact with. + The handler to execute while a transaction is pending. Returning true signals to commit the transaction. + The value of the awaited action. + + + + Begins a transaction before executing the action. Commits if there are no exceptions. Otherwise rolls-back the transaction. + + The value returned from the action. + The connection to transact with. + The handler to execute while a transaction is pending. + The value of the awaited action. + + + + Begins a transaction before executing the action. Commits if there are no exceptions. Otherwise rolls-back the transaction. + + The connection to transact with. + The handler to execute while a transaction is pending. + Default SqlConnectionFactory for generating SqlConnections. diff --git a/docs/README.html b/docs/README.html index 3618997..8607a0b 100644 --- a/docs/README.html +++ b/docs/README.html @@ -118,7 +118,28 @@

AsSourceBlockAsync<T&

AsSourceBlockAsync<T>() is fully asynchronous from end-to-end and can keep total buffering to a minimum by consuming (receiving) results as fast as possible, but may incur additional latency between reads.

ResultsAsync<T>() is fully asynchronous from end-to-end but returns an IEnumerable<T> that although has fully buffered the all the data into memory, has deferred the transformation until enumerated. This way, the asynchronous data pipeline is fully complete before synchronously transforming the data.

Both methods ultimately are using a Queue<object[]> or ConcurrentQueue<object[]> (Dataflow) to buffer the data, but ResultsAsync<T>() buffers the entire data set before dequeuing and transforming the results.

- +

Transactions

+

Example:

+
    // Returns true if the transaction is successful.
+    public static bool TryTransaction()
+    => ConnectionFactory.Using(connection =>
+        // Open a connection and start a transaction.
+        connection.ExecuteTransactionConditional(transaction => {
+
+            // First procedure does some updates.
+            var count = transaction
+                .StoredProcedure("[Updated Procedure]")
+                .ExecuteNonQuery();
+
+            // Second procedure validates the results.
+            // If it returns true, then the transaction is commited.
+            // If it returns false, then the transaction is rolled back.
+            return transaction
+                .StoredProcedure("[Validation Procedure]")
+                .AddParam("@ExpectedCount", count)
+                .ExecuteScalar<bool>();
+        }));
+