Class DataConnectionExtensions
Contains extension methods for DataConnection class.
public static class DataConnectionExtensions
- Inheritance
-
DataConnectionExtensions
Methods
BulkCopyAsync<T>(DataConnection, BulkCopyOptions, IEnumerable<T>, CancellationToken)
Asynchronously performs bulk insert operation.
public static Task<BulkCopyRowsCopied> BulkCopyAsync<T>(this DataConnection dataConnection, BulkCopyOptions options, IEnumerable<T> source, CancellationToken cancellationToken = default) where T : class
Parameters
dataConnectionDataConnectionDatabase connection.
optionsBulkCopyOptionsOperation options.
sourceIEnumerable<T>Records to insert.
cancellationTokenCancellationTokenAsynchronous operation cancellation token.
Returns
- Task<BulkCopyRowsCopied>
Task with bulk insert operation status.
Type Parameters
TMapping type of inserted record.
BulkCopyAsync<T>(DataConnection, IEnumerable<T>, CancellationToken)
Asynchronously performs bulk insert operation.
public static Task<BulkCopyRowsCopied> BulkCopyAsync<T>(this DataConnection dataConnection, IEnumerable<T> source, CancellationToken cancellationToken = default) where T : class
Parameters
dataConnectionDataConnectionDatabase connection.
sourceIEnumerable<T>Records to insert.
cancellationTokenCancellationTokenAsynchronous operation cancellation token.
Returns
- Task<BulkCopyRowsCopied>
Task with bulk insert operation status.
Type Parameters
TMapping type of inserted record.
BulkCopyAsync<T>(DataConnection, int, IEnumerable<T>, CancellationToken)
Asynchronously performs bulk insert operation.
public static Task<BulkCopyRowsCopied> BulkCopyAsync<T>(this DataConnection dataConnection, int maxBatchSize, IEnumerable<T> source, CancellationToken cancellationToken = default) where T : class
Parameters
dataConnectionDataConnectionDatabase connection.
maxBatchSizeintNumber of rows in each batch. At the end of each batch, the rows in the batch are sent to the server.
sourceIEnumerable<T>Records to insert.
cancellationTokenCancellationTokenAsynchronous operation cancellation token.
Returns
- Task<BulkCopyRowsCopied>
Task with bulk insert operation status.
Type Parameters
TMapping type of inserted record.
BulkCopyAsync<T>(ITable<T>, BulkCopyOptions, IEnumerable<T>, CancellationToken)
Asynchronously performs bulk insert operation into table specified in options parameter or into table, identified by table.
public static Task<BulkCopyRowsCopied> BulkCopyAsync<T>(this ITable<T> table, BulkCopyOptions options, IEnumerable<T> source, CancellationToken cancellationToken = default) where T : notnull
Parameters
tableITable<T>Target table.
optionsBulkCopyOptionsOperation options.
sourceIEnumerable<T>Records to insert.
cancellationTokenCancellationTokenAsynchronous operation cancellation token.
Returns
- Task<BulkCopyRowsCopied>
Task with bulk insert operation status.
Type Parameters
TMapping type of inserted record.
BulkCopyAsync<T>(ITable<T>, IEnumerable<T>, CancellationToken)
Asynchronously performs bulk insert operation into table, identified by table.
public static Task<BulkCopyRowsCopied> BulkCopyAsync<T>(this ITable<T> table, IEnumerable<T> source, CancellationToken cancellationToken = default) where T : notnull
Parameters
tableITable<T>Target table.
sourceIEnumerable<T>Records to insert.
cancellationTokenCancellationTokenAsynchronous operation cancellation token.
Returns
- Task<BulkCopyRowsCopied>
Task with bulk insert operation status.
Type Parameters
TMapping type of inserted record.
BulkCopyAsync<T>(ITable<T>, int, IEnumerable<T>, CancellationToken)
Asynchronously performs bulk insert operation into table, identified by table.
public static Task<BulkCopyRowsCopied> BulkCopyAsync<T>(this ITable<T> table, int maxBatchSize, IEnumerable<T> source, CancellationToken cancellationToken = default) where T : notnull
Parameters
tableITable<T>Target table.
maxBatchSizeintNumber of rows in each batch. At the end of each batch, the rows in the batch are sent to the server.
sourceIEnumerable<T>Records to insert.
cancellationTokenCancellationTokenAsynchronous operation cancellation token.
Returns
- Task<BulkCopyRowsCopied>
Task with bulk insert operation status.
Type Parameters
TMapping type of inserted record.
BulkCopy<T>(DataConnection, BulkCopyOptions, IEnumerable<T>)
Performs bulk insert operation.
public static BulkCopyRowsCopied BulkCopy<T>(this DataConnection dataConnection, BulkCopyOptions options, IEnumerable<T> source) where T : class
Parameters
dataConnectionDataConnectionDatabase connection.
optionsBulkCopyOptionsOperation options.
sourceIEnumerable<T>Records to insert.
Returns
- BulkCopyRowsCopied
Bulk insert operation status.
Type Parameters
TMapping type of inserted record.
BulkCopy<T>(DataConnection, IEnumerable<T>)
Performs bulk insert operation.
public static BulkCopyRowsCopied BulkCopy<T>(this DataConnection dataConnection, IEnumerable<T> source) where T : class
Parameters
dataConnectionDataConnectionDatabase connection.
sourceIEnumerable<T>Records to insert.
Returns
- BulkCopyRowsCopied
Bulk insert operation status.
Type Parameters
TMapping type of inserted record.
BulkCopy<T>(DataConnection, int, IEnumerable<T>)
Performs bulk insert operation.
public static BulkCopyRowsCopied BulkCopy<T>(this DataConnection dataConnection, int maxBatchSize, IEnumerable<T> source) where T : class
Parameters
dataConnectionDataConnectionDatabase connection.
maxBatchSizeintNumber of rows in each batch. At the end of each batch, the rows in the batch are sent to the server.
sourceIEnumerable<T>Records to insert.
Returns
- BulkCopyRowsCopied
Bulk insert operation status.
Type Parameters
TMapping type of inserted record.
BulkCopy<T>(ITable<T>, BulkCopyOptions, IEnumerable<T>)
Performs bulk insert operation into table specified in options parameter or into table, identified by table.
public static BulkCopyRowsCopied BulkCopy<T>(this ITable<T> table, BulkCopyOptions options, IEnumerable<T> source) where T : notnull
Parameters
tableITable<T>Target table.
optionsBulkCopyOptionsOperation options.
sourceIEnumerable<T>Records to insert.
Returns
- BulkCopyRowsCopied
Bulk insert operation status.
Type Parameters
TMapping type of inserted record.
BulkCopy<T>(ITable<T>, IEnumerable<T>)
Performs bulk insert operation into table, identified by table.
public static BulkCopyRowsCopied BulkCopy<T>(this ITable<T> table, IEnumerable<T> source) where T : notnull
Parameters
tableITable<T>Target table.
sourceIEnumerable<T>Records to insert.
Returns
- BulkCopyRowsCopied
Bulk insert operation status.
Type Parameters
TMapping type of inserted record.
BulkCopy<T>(ITable<T>, int, IEnumerable<T>)
Performs bulk insert operation into table, identified by table.
public static BulkCopyRowsCopied BulkCopy<T>(this ITable<T> table, int maxBatchSize, IEnumerable<T> source) where T : notnull
Parameters
tableITable<T>Target table.
maxBatchSizeintNumber of rows in each batch. At the end of each batch, the rows in the batch are sent to the server.
sourceIEnumerable<T>Records to insert.
Returns
- BulkCopyRowsCopied
Bulk insert operation status.
Type Parameters
TMapping type of inserted record.
Execute(DataConnection, string)
Executes command and returns number of affected records.
public static int Execute(this DataConnection connection, string sql)
Parameters
connectionDataConnectionDatabase connection.
sqlstringCommand text.
Returns
- int
Number of records, affected by command execution.
Execute(DataConnection, string, params DataParameter[])
Executes command and returns number of affected records.
public static int Execute(this DataConnection connection, string sql, params DataParameter[] parameters)
Parameters
connectionDataConnectionDatabase connection.
sqlstringCommand text.
parametersDataParameter[]Command parameters.
Returns
- int
Number of records, affected by command execution.
Execute(DataConnection, string, object?)
Executes command and returns number of affected records.
public static int Execute(this DataConnection connection, string sql, object? parameters)
Parameters
connectionDataConnectionDatabase connection.
sqlstringCommand text.
parametersobjectCommand parameters. Supported values:
-
nullfor command without parameters;- single DataParameter instance;
- array of DataParameter parameters;
- mapping class entity.
Last case will convert all mapped columns to DataParameter instances using following logic:
- if column is of DataParameter type, column value will be used. If parameter name (Name) is not set, column name will be used;
- if converter from column type to DataParameter is defined in mapping schema, it will be used to create parameter with column name passed to converter;
- otherwise column value will be converted to DataParameter using column name as parameter name and column value will be converted to parameter value using conversion, defined by mapping schema.
Returns
- int
Number of records, affected by command execution.
ExecuteAsync(DataConnection, string)
Executes command asynchronously and returns number of affected records.
public static Task<int> ExecuteAsync(this DataConnection connection, string sql)
Parameters
connectionDataConnectionDatabase connection.
sqlstringCommand text.
Returns
ExecuteAsync(DataConnection, string, params DataParameter[])
Executes command asynchronously and returns number of affected records.
public static Task<int> ExecuteAsync(this DataConnection connection, string sql, params DataParameter[] parameters)
Parameters
connectionDataConnectionDatabase connection.
sqlstringCommand text.
parametersDataParameter[]Command parameters.
Returns
ExecuteAsync(DataConnection, string, object?)
Executes command asynchronously and returns number of affected records.
public static Task<int> ExecuteAsync(this DataConnection connection, string sql, object? parameters)
Parameters
connectionDataConnectionDatabase connection.
sqlstringCommand text.
parametersobjectCommand parameters. Supported values:
-
nullfor command without parameters;- single DataParameter instance;
- array of DataParameter parameters;
- mapping class entity.
Last case will convert all mapped columns to DataParameter instances using following logic:
- if column is of DataParameter type, column value will be used. If parameter name (Name) is not set, column name will be used;
- if converter from column type to DataParameter is defined in mapping schema, it will be used to create parameter with column name passed to converter;
- otherwise column value will be converted to DataParameter using column name as parameter name and column value will be converted to parameter value using conversion, defined by mapping schema.
Returns
ExecuteAsync(DataConnection, string, CancellationToken)
Executes command asynchronously and returns number of affected records.
public static Task<int> ExecuteAsync(this DataConnection connection, string sql, CancellationToken cancellationToken)
Parameters
connectionDataConnectionDatabase connection.
sqlstringCommand text.
cancellationTokenCancellationTokenAsynchronous operation cancellation token.
Returns
ExecuteAsync(DataConnection, string, CancellationToken, params DataParameter[])
Executes command asynchronously and returns number of affected records.
public static Task<int> ExecuteAsync(this DataConnection connection, string sql, CancellationToken cancellationToken, params DataParameter[] parameters)
Parameters
connectionDataConnectionDatabase connection.
sqlstringCommand text.
cancellationTokenCancellationTokenAsynchronous operation cancellation token.
parametersDataParameter[]Command parameters.
Returns
ExecuteAsync(DataConnection, string, CancellationToken, object?)
Executes command asynchronously and returns number of affected records.
public static Task<int> ExecuteAsync(this DataConnection connection, string sql, CancellationToken cancellationToken, object? parameters)
Parameters
connectionDataConnectionDatabase connection.
sqlstringCommand text.
cancellationTokenCancellationTokenAsynchronous operation cancellation token.
parametersobjectCommand parameters. Supported values:
-
nullfor command without parameters;- single DataParameter instance;
- array of DataParameter parameters;
- mapping class entity.
Last case will convert all mapped columns to DataParameter instances using following logic:
- if column is of DataParameter type, column value will be used. If parameter name (Name) is not set, column name will be used;
- if converter from column type to DataParameter is defined in mapping schema, it will be used to create parameter with column name passed to converter;
- otherwise column value will be converted to DataParameter using column name as parameter name and column value will be converted to parameter value using conversion, defined by mapping schema.
Returns
ExecuteAsync<T>(DataConnection, string)
Executes command asynchronously and returns single value.
public static Task<T> ExecuteAsync<T>(this DataConnection connection, string sql)
Parameters
connectionDataConnectionDatabase connection.
sqlstringCommand text.
Returns
- Task<T>
Task with resulting value.
Type Parameters
TResulting value type.
ExecuteAsync<T>(DataConnection, string, DataParameter)
Executes command asynchronously and returns single value.
public static Task<T> ExecuteAsync<T>(this DataConnection connection, string sql, DataParameter parameter)
Parameters
connectionDataConnectionDatabase connection.
sqlstringCommand text.
parameterDataParameterCommand parameter.
Returns
- Task<T>
Task with resulting value.
Type Parameters
TResulting value type.
ExecuteAsync<T>(DataConnection, string, DataParameter, CancellationToken)
Executes command asynchronously and returns single value.
public static Task<T> ExecuteAsync<T>(this DataConnection connection, string sql, DataParameter parameter, CancellationToken cancellationToken)
Parameters
connectionDataConnectionDatabase connection.
sqlstringCommand text.
parameterDataParameterCommand parameter.
cancellationTokenCancellationTokenAsynchronous operation cancellation token.
Returns
- Task<T>
Task with resulting value.
Type Parameters
TResulting value type.
ExecuteAsync<T>(DataConnection, string, params DataParameter[])
Executes command asynchronously and returns single value.
public static Task<T> ExecuteAsync<T>(this DataConnection connection, string sql, params DataParameter[] parameters)
Parameters
connectionDataConnectionDatabase connection.
sqlstringCommand text.
parametersDataParameter[]Command parameters.
Returns
- Task<T>
Task with resulting value.
Type Parameters
TResulting value type.
ExecuteAsync<T>(DataConnection, string, object?)
Executes command asynchronously and returns single value.
public static Task<T> ExecuteAsync<T>(this DataConnection connection, string sql, object? parameters)
Parameters
connectionDataConnectionDatabase connection.
sqlstringCommand text.
parametersobjectCommand parameters. Supported values:
-
nullfor command without parameters;- single DataParameter instance;
- array of DataParameter parameters;
- mapping class entity.
Last case will convert all mapped columns to DataParameter instances using following logic:
- if column is of DataParameter type, column value will be used. If parameter name (Name) is not set, column name will be used;
- if converter from column type to DataParameter is defined in mapping schema, it will be used to create parameter with column name passed to converter;
- otherwise column value will be converted to DataParameter using column name as parameter name and column value will be converted to parameter value using conversion, defined by mapping schema.
Returns
- Task<T>
Task with resulting value.
Type Parameters
TResulting value type.
ExecuteAsync<T>(DataConnection, string, CancellationToken)
Executes command asynchronously and returns single value.
public static Task<T> ExecuteAsync<T>(this DataConnection connection, string sql, CancellationToken cancellationToken)
Parameters
connectionDataConnectionDatabase connection.
sqlstringCommand text.
cancellationTokenCancellationTokenAsynchronous operation cancellation token.
Returns
- Task<T>
Task with resulting value.
Type Parameters
TResulting value type.
ExecuteAsync<T>(DataConnection, string, CancellationToken, params DataParameter[])
Executes command asynchronously and returns single value.
public static Task<T> ExecuteAsync<T>(this DataConnection connection, string sql, CancellationToken cancellationToken, params DataParameter[] parameters)
Parameters
connectionDataConnectionDatabase connection.
sqlstringCommand text.
cancellationTokenCancellationTokenAsynchronous operation cancellation token.
parametersDataParameter[]Command parameters.
Returns
- Task<T>
Task with resulting value.
Type Parameters
TResulting value type.
ExecuteAsync<T>(DataConnection, string, CancellationToken, object?)
Executes command asynchronously and returns single value.
public static Task<T> ExecuteAsync<T>(this DataConnection connection, string sql, CancellationToken cancellationToken, object? parameters)
Parameters
connectionDataConnectionDatabase connection.
sqlstringCommand text.
cancellationTokenCancellationTokenAsynchronous operation cancellation token.
parametersobjectCommand parameters. Supported values:
-
nullfor command without parameters;- single DataParameter instance;
- array of DataParameter parameters;
- mapping class entity.
Last case will convert all mapped columns to DataParameter instances using following logic:
- if column is of DataParameter type, column value will be used. If parameter name (Name) is not set, column name will be used;
- if converter from column type to DataParameter is defined in mapping schema, it will be used to create parameter with column name passed to converter;
- otherwise column value will be converted to DataParameter using column name as parameter name and column value will be converted to parameter value using conversion, defined by mapping schema.
Returns
- Task<T>
Task with resulting value.
Type Parameters
TResulting value type.
ExecuteProc(DataConnection, string, params DataParameter[])
Executes command using StoredProcedure command type and returns number of affected records.
Sets result values for output and reference parameters to corresponding parameters in parameters.
public static int ExecuteProc(this DataConnection connection, string sql, params DataParameter[] parameters)
Parameters
connectionDataConnectionDatabase connection.
sqlstringCommand text. This is caller's responsibility to properly escape procedure name.
parametersDataParameter[]Command parameters.
Returns
- int
Number of records, affected by command execution.
ExecuteProc(DataConnection, string, object?)
Executes command using StoredProcedure command type and returns number of affected records.
public static int ExecuteProc(this DataConnection connection, string sql, object? parameters)
Parameters
connectionDataConnectionDatabase connection.
sqlstringCommand text. This is caller's responsibility to properly escape procedure name.
parametersobjectCommand parameters. Supported values:
-
nullfor command without parameters;- single DataParameter instance;
- array of DataParameter parameters;
- mapping class entity.
Last case will convert all mapped columns to DataParameter instances using following logic:
- if column is of DataParameter type, column value will be used. If parameter name (Name) is not set, column name will be used;
- if converter from column type to DataParameter is defined in mapping schema, it will be used to create parameter with column name passed to converter;
- otherwise column value will be converted to DataParameter using column name as parameter name and column value will be converted to parameter value using conversion, defined by mapping schema.
Returns
- int
Number of records, affected by command execution.
ExecuteProcAsync(DataConnection, string, params DataParameter[])
Executes command using StoredProcedure command type asynchronously and returns number of affected records.
Sets result values for output and reference parameters to corresponding parameters in parameters.
public static Task<int> ExecuteProcAsync(this DataConnection connection, string sql, params DataParameter[] parameters)
Parameters
connectionDataConnectionDatabase connection.
sqlstringCommand text. This is caller's responsibility to properly escape procedure name.
parametersDataParameter[]Command parameters.
Returns
ExecuteProcAsync(DataConnection, string, object?)
Executes command using StoredProcedure command type asynchronously and returns number of affected records.
public static Task<int> ExecuteProcAsync(this DataConnection connection, string sql, object? parameters)
Parameters
connectionDataConnectionDatabase connection.
sqlstringCommand text. This is caller's responsibility to properly escape procedure name.
parametersobjectCommand parameters. Supported values:
-
nullfor command without parameters;- single DataParameter instance;
- array of DataParameter parameters;
- mapping class entity.
Last case will convert all mapped columns to DataParameter instances using following logic:
- if column is of DataParameter type, column value will be used. If parameter name (Name) is not set, column name will be used;
- if converter from column type to DataParameter is defined in mapping schema, it will be used to create parameter with column name passed to converter;
- otherwise column value will be converted to DataParameter using column name as parameter name and column value will be converted to parameter value using conversion, defined by mapping schema.
Returns
ExecuteProcAsync(DataConnection, string, CancellationToken, params DataParameter[])
Executes command using StoredProcedure command type asynchronously and returns number of affected records.
public static Task<int> ExecuteProcAsync(this DataConnection connection, string sql, CancellationToken cancellationToken, params DataParameter[] parameters)
Parameters
connectionDataConnectionDatabase connection.
sqlstringCommand text. This is caller's responsibility to properly escape procedure name.
cancellationTokenCancellationTokenAsynchronous operation cancellation token.
parametersDataParameter[]Command parameters.
Returns
ExecuteProcAsync(DataConnection, string, CancellationToken, object?)
Executes command using StoredProcedure command type asynchronously and returns number of affected records.
public static Task<int> ExecuteProcAsync(this DataConnection connection, string sql, CancellationToken cancellationToken, object? parameters)
Parameters
connectionDataConnectionDatabase connection.
sqlstringCommand text. This is caller's responsibility to properly escape procedure name.
cancellationTokenCancellationTokenAsynchronous operation cancellation token.
parametersobjectCommand parameters. Supported values:
-
nullfor command without parameters;- single DataParameter instance;
- array of DataParameter parameters;
- mapping class entity.
Last case will convert all mapped columns to DataParameter instances using following logic:
- if column is of DataParameter type, column value will be used. If parameter name (Name) is not set, column name will be used;
- if converter from column type to DataParameter is defined in mapping schema, it will be used to create parameter with column name passed to converter;
- otherwise column value will be converted to DataParameter using column name as parameter name and column value will be converted to parameter value using conversion, defined by mapping schema.
Returns
ExecuteProcAsync<T>(DataConnection, string, params DataParameter[])
Executes command using StoredProcedure command type asynchronously and returns single value.
Sets result values for output and reference parameters to corresponding parameters in parameters.
public static Task<T> ExecuteProcAsync<T>(this DataConnection connection, string sql, params DataParameter[] parameters)
Parameters
connectionDataConnectionDatabase connection.
sqlstringCommand text. This is caller's responsibility to properly escape procedure name.
parametersDataParameter[]Command parameters.
Returns
- Task<T>
Task with resulting value.
Type Parameters
TResulting value type.
ExecuteProcAsync<T>(DataConnection, string, object?)
Executes command using StoredProcedure command type asynchronously and returns single value.
public static Task<T> ExecuteProcAsync<T>(this DataConnection connection, string sql, object? parameters)
Parameters
connectionDataConnectionDatabase connection.
sqlstringCommand text. This is caller's responsibility to properly escape procedure name.
parametersobjectCommand parameters. Supported values:
-
nullfor command without parameters;- single DataParameter instance;
- array of DataParameter parameters;
- mapping class entity.
Last case will convert all mapped columns to DataParameter instances using following logic:
- if column is of DataParameter type, column value will be used. If parameter name (Name) is not set, column name will be used;
- if converter from column type to DataParameter is defined in mapping schema, it will be used to create parameter with column name passed to converter;
- otherwise column value will be converted to DataParameter using column name as parameter name and column value will be converted to parameter value using conversion, defined by mapping schema.
Returns
- Task<T>
Task with resulting value.
Type Parameters
TResulting value type.
ExecuteProcAsync<T>(DataConnection, string, CancellationToken, params DataParameter[])
Executes command using StoredProcedure command type asynchronously and returns single value.
public static Task<T> ExecuteProcAsync<T>(this DataConnection connection, string sql, CancellationToken cancellationToken, params DataParameter[] parameters)
Parameters
connectionDataConnectionDatabase connection.
sqlstringCommand text. This is caller's responsibility to properly escape procedure name.
cancellationTokenCancellationTokenAsynchronous operation cancellation token.
parametersDataParameter[]Command parameters.
Returns
- Task<T>
Resulting value.
Type Parameters
TResulting value type.
ExecuteProcAsync<T>(DataConnection, string, CancellationToken, object?)
Executes command using StoredProcedure command type asynchronously and returns single value.
public static Task<T> ExecuteProcAsync<T>(this DataConnection connection, string sql, CancellationToken cancellationToken, object? parameters)
Parameters
connectionDataConnectionDatabase connection.
sqlstringCommand text. This is caller's responsibility to properly escape procedure name.
cancellationTokenCancellationTokenAsynchronous operation cancellation token.
parametersobjectCommand parameters. Supported values:
-
nullfor command without parameters;- single DataParameter instance;
- array of DataParameter parameters;
- mapping class entity.
Last case will convert all mapped columns to DataParameter instances using following logic:
- if column is of DataParameter type, column value will be used. If parameter name (Name) is not set, column name will be used;
- if converter from column type to DataParameter is defined in mapping schema, it will be used to create parameter with column name passed to converter;
- otherwise column value will be converted to DataParameter using column name as parameter name and column value will be converted to parameter value using conversion, defined by mapping schema.
Returns
- Task<T>
Resulting value.
Type Parameters
TResulting value type.
ExecuteProc<T>(DataConnection, string, params DataParameter[])
Executes command using StoredProcedure command type and returns single value.
Sets result values for output and reference parameters to corresponding parameters in parameters.
public static T ExecuteProc<T>(this DataConnection connection, string sql, params DataParameter[] parameters)
Parameters
connectionDataConnectionDatabase connection.
sqlstringCommand text. This is caller's responsibility to properly escape procedure name.
parametersDataParameter[]Command parameters.
Returns
- T
Resulting value.
Type Parameters
TResulting value type.
ExecuteProc<T>(DataConnection, string, object?)
Executes command using StoredProcedure command type and returns single value.
public static T ExecuteProc<T>(this DataConnection connection, string sql, object? parameters)
Parameters
connectionDataConnectionDatabase connection.
sqlstringCommand text. This is caller's responsibility to properly escape procedure name.
parametersobjectCommand parameters. Supported values:
-
nullfor command without parameters;- single DataParameter instance;
- array of DataParameter parameters;
- mapping class entity.
Last case will convert all mapped columns to DataParameter instances using following logic:
- if column is of DataParameter type, column value will be used. If parameter name (Name) is not set, column name will be used;
- if converter from column type to DataParameter is defined in mapping schema, it will be used to create parameter with column name passed to converter;
- otherwise column value will be converted to DataParameter using column name as parameter name and column value will be converted to parameter value using conversion, defined by mapping schema.
Returns
- T
Resulting value.
Type Parameters
TResulting value type.
ExecuteReader(DataConnection, string)
Executes command and returns data reader instance.
public static DataReader ExecuteReader(this DataConnection connection, string sql)
Parameters
connectionDataConnectionDatabase connection.
sqlstringCommand text.
Returns
- DataReader
Data reader object.
ExecuteReader(DataConnection, string, DataParameter)
Executes command and returns data reader instance.
public static DataReader ExecuteReader(this DataConnection connection, string sql, DataParameter parameter)
Parameters
connectionDataConnectionDatabase connection.
sqlstringCommand text.
parameterDataParameterCommand parameter.
Returns
- DataReader
Data reader object.
ExecuteReader(DataConnection, string, params DataParameter[])
Executes command and returns data reader instance.
public static DataReader ExecuteReader(this DataConnection connection, string sql, params DataParameter[] parameters)
Parameters
connectionDataConnectionDatabase connection.
sqlstringCommand text.
parametersDataParameter[]Command parameters.
Returns
- DataReader
Data reader object.
ExecuteReader(DataConnection, string, CommandType, CommandBehavior, params DataParameter[])
Executes command and returns data reader instance.
public static DataReader ExecuteReader(this DataConnection connection, string sql, CommandType commandType, CommandBehavior commandBehavior, params DataParameter[] parameters)
Parameters
connectionDataConnectionDatabase connection.
sqlstringCommand text.
commandTypeCommandTypeType of command. See CommandType for all supported types.
commandBehaviorCommandBehaviorCommand behavior flags. See CommandBehavior for more details.
parametersDataParameter[]Command parameters.
Returns
- DataReader
Data reader object.
ExecuteReader(DataConnection, string, object?)
Executes command and returns data reader instance.
public static DataReader ExecuteReader(this DataConnection connection, string sql, object? parameters)
Parameters
connectionDataConnectionDatabase connection.
sqlstringCommand text.
parametersobjectCommand parameters. Supported values:
-
nullfor command without parameters;- single DataParameter instance;
- array of DataParameter parameters;
- mapping class entity.
Last case will convert all mapped columns to DataParameter instances using following logic:
- if column is of DataParameter type, column value will be used. If parameter name (Name) is not set, column name will be used;
- if converter from column type to DataParameter is defined in mapping schema, it will be used to create parameter with column name passed to converter;
- otherwise column value will be converted to DataParameter using column name as parameter name and column value will be converted to parameter value using conversion, defined by mapping schema.
Returns
- DataReader
Data reader object.
Execute<T>(DataConnection, string)
Executes command and returns single value.
public static T Execute<T>(this DataConnection connection, string sql)
Parameters
connectionDataConnectionDatabase connection.
sqlstringCommand text.
Returns
- T
Resulting value.
Type Parameters
TResulting value type.
Execute<T>(DataConnection, string, DataParameter)
Executes command and returns single value.
public static T Execute<T>(this DataConnection connection, string sql, DataParameter parameter)
Parameters
connectionDataConnectionDatabase connection.
sqlstringCommand text.
parameterDataParameterCommand parameter.
Returns
- T
Resulting value.
Type Parameters
TResulting value type.
Execute<T>(DataConnection, string, params DataParameter[])
Executes command and returns single value.
public static T Execute<T>(this DataConnection connection, string sql, params DataParameter[] parameters)
Parameters
connectionDataConnectionDatabase connection.
sqlstringCommand text.
parametersDataParameter[]Command parameters.
Returns
- T
Resulting value.
Type Parameters
TResulting value type.
Execute<T>(DataConnection, string, object?)
Executes command and returns single value.
public static T Execute<T>(this DataConnection connection, string sql, object? parameters)
Parameters
connectionDataConnectionDatabase connection.
sqlstringCommand text.
parametersobjectCommand parameters. Supported values:
-
nullfor command without parameters;- single DataParameter instance;
- array of DataParameter parameters;
- mapping class entity.
Last case will convert all mapped columns to DataParameter instances using following logic:
- if column is of DataParameter type, column value will be used. If parameter name (Name) is not set, column name will be used;
- if converter from column type to DataParameter is defined in mapping schema, it will be used to create parameter with column name passed to converter;
- otherwise column value will be converted to DataParameter using column name as parameter name and column value will be converted to parameter value using conversion, defined by mapping schema.
Returns
- T
Resulting value.
Type Parameters
TResulting value type.
MergeAsync<T>(DataConnection, bool, IEnumerable<T>, string?, string?, string?, string?, TableOptions, CancellationToken)
Executes following merge operations asynchronously in specified order:
- Update
- Insert
- Delete By Source (optional).
If delete operation enabled by
deleteparameter - method could be used only with SQL Server.
[Obsolete("Legacy Merge API obsoleted and will be removed in future versions. See migration guide https://linq2db.github.io/articles/sql/merge/Merge-API-Migration.html or direct translation of old API to new one in code of this method https://github.com/linq2db/linq2db/blob/master/Source/LinqToDB/Data/DataConnectionExtensions.LegacyMerge.cs.")]
public static Task<int> MergeAsync<T>(this DataConnection dataConnection, bool delete, IEnumerable<T> source, string? tableName = null, string? databaseName = null, string? schemaName = null, string? serverName = null, TableOptions tableOptions = TableOptions.NotSet, CancellationToken cancellationToken = default) where T : class
Parameters
dataConnectionDataConnectionData connection instance.
deleteboolIf true, merge command will include delete by source operation without condition.
sourceIEnumerable<T>Source data to merge into target table.
tableNamestringOptional target table name.
databaseNamestringOptional target table's database name.
schemaNamestringOptional target table's schema name.
serverNamestringOptional name of linked server. If not specified, value from mapping will be used.
tableOptionsTableOptionsTable options. See TableOptions enum for support information per provider.
cancellationTokenCancellationTokenOptional asynchronous operation cancellation token.
Returns
Type Parameters
TTarget table mapping class.
MergeAsync<T>(DataConnection, IEnumerable<T>, string?, string?, string?, string?, TableOptions, CancellationToken)
Executes following merge operations asynchronously in specified order:
- Update
- Insert.
[Obsolete("Legacy Merge API obsoleted and will be removed in future versions. See migration guide https://linq2db.github.io/articles/sql/merge/Merge-API-Migration.html or direct translation of old API to new one in code of this method https://github.com/linq2db/linq2db/blob/master/Source/LinqToDB/Data/DataConnectionExtensions.LegacyMerge.cs.")]
public static Task<int> MergeAsync<T>(this DataConnection dataConnection, IEnumerable<T> source, string? tableName = null, string? databaseName = null, string? schemaName = null, string? serverName = null, TableOptions tableOptions = TableOptions.NotSet, CancellationToken cancellationToken = default) where T : class
Parameters
dataConnectionDataConnectionData connection instance.
sourceIEnumerable<T>Source data to merge into target table.
tableNamestringOptional target table name.
databaseNamestringOptional target table's database name.
schemaNamestringOptional target table's schema name.
serverNamestringOptional name of linked server. If not specified, value from mapping will be used.
tableOptionsTableOptionsTable options. See TableOptions enum for support information per provider.
cancellationTokenCancellationTokenOptional asynchronous operation cancellation token.
Returns
Type Parameters
TTarget table mapping class.
MergeAsync<T>(DataConnection, Expression<Func<T, bool>>, IEnumerable<T>, string?, string?, string?, string?, TableOptions, CancellationToken)
Executes following merge operations asynchronously in specified order:
- Update
- Insert
- Delete By Source. Method could be used only with SQL Server.
[Obsolete("Legacy Merge API obsoleted and will be removed in future versions. See migration guide https://linq2db.github.io/articles/sql/merge/Merge-API-Migration.html or direct translation of old API to new one in code of this method https://github.com/linq2db/linq2db/blob/master/Source/LinqToDB/Data/DataConnectionExtensions.LegacyMerge.cs.")]
public static Task<int> MergeAsync<T>(this DataConnection dataConnection, Expression<Func<T, bool>> predicate, IEnumerable<T> source, string? tableName = null, string? databaseName = null, string? schemaName = null, string? serverName = null, TableOptions tableOptions = TableOptions.NotSet, CancellationToken cancellationToken = default) where T : class
Parameters
dataConnectionDataConnectionData connection instance.
predicateExpression<Func<T, bool>>Filter, applied to delete operation. Optional.
sourceIEnumerable<T>Source data to merge into target table.
tableNamestringOptional target table name.
databaseNamestringOptional target table's database name.
schemaNamestringOptional target table's schema name.
serverNamestringOptional name of linked server. If not specified, value from mapping will be used.
tableOptionsTableOptionsTable options. See TableOptions enum for support information per provider.
cancellationTokenCancellationTokenOptional asynchronous operation cancellation token.
Returns
Type Parameters
TTarget table mapping class.
MergeAsync<T>(DataConnection, IQueryable<T>, Expression<Func<T, bool>>, string?, string?, string?, string?, TableOptions, CancellationToken)
Executes following merge operations asynchronously in specified order:
- Update
- Insert
- Delete By Source. Method could be used only with SQL Server.
[Obsolete("Legacy Merge API obsoleted and will be removed in future versions. See migration guide https://linq2db.github.io/articles/sql/merge/Merge-API-Migration.html or direct translation of old API to new one in code of this method https://github.com/linq2db/linq2db/blob/master/Source/LinqToDB/Data/DataConnectionExtensions.LegacyMerge.cs.")]
public static Task<int> MergeAsync<T>(this DataConnection dataConnection, IQueryable<T> source, Expression<Func<T, bool>> predicate, string? tableName = null, string? databaseName = null, string? schemaName = null, string? serverName = null, TableOptions tableOptions = TableOptions.NotSet, CancellationToken cancellationToken = default) where T : class
Parameters
dataConnectionDataConnectionData connection instance.
sourceIQueryable<T>Source data to merge into target table. All source data will be loaded from server for command generation.
predicateExpression<Func<T, bool>>Filter, applied both to source and delete operation. Required.
tableNamestringOptional target table name.
databaseNamestringOptional target table's database name.
schemaNamestringOptional target table's schema name.
serverNamestringOptional name of linked server. If not specified, value from mapping will be used.
tableOptionsTableOptionsTable options. See TableOptions enum for support information per provider.
cancellationTokenCancellationTokenOptional asynchronous operation cancellation token.
Returns
Type Parameters
TTarget table mapping class.
MergeAsync<T>(ITable<T>, bool, IEnumerable<T>, string?, string?, string?, string?, TableOptions, CancellationToken)
Executes following merge operations asynchronously in specified order:
- Update
- Insert
- Delete By Source (optional).
If delete operation enabled by
deleteparameter - method could be used only with SQL Server.
[Obsolete("Legacy Merge API obsoleted and will be removed in future versions. See migration guide https://linq2db.github.io/articles/sql/merge/Merge-API-Migration.html or direct translation of old API to new one in code of this method https://github.com/linq2db/linq2db/blob/master/Source/LinqToDB/Data/DataConnectionExtensions.LegacyMerge.cs.")]
public static Task<int> MergeAsync<T>(this ITable<T> table, bool delete, IEnumerable<T> source, string? tableName = null, string? databaseName = null, string? schemaName = null, string? serverName = null, TableOptions tableOptions = TableOptions.NotSet, CancellationToken cancellationToken = default) where T : class
Parameters
tableITable<T>Target table.
deleteboolIf true, merge command will include delete by source operation without condition.
sourceIEnumerable<T>Source data to merge into target table.
tableNamestringOptional target table name.
databaseNamestringOptional target table's database name.
schemaNamestringOptional target table's schema name.
serverNamestringOptional name of linked server. If not specified, value from mapping will be used.
tableOptionsTableOptionsTable options. See TableOptions enum for support information per provider.
cancellationTokenCancellationTokenOptional asynchronous operation cancellation token.
Returns
Type Parameters
TTarget table mapping class.
MergeAsync<T>(ITable<T>, IEnumerable<T>, string?, string?, string?, string?, TableOptions, CancellationToken)
Executes following merge operations asynchronously in specified order:
- Update
- Insert.
[Obsolete("Legacy Merge API obsoleted and will be removed in future versions. See migration guide https://linq2db.github.io/articles/sql/merge/Merge-API-Migration.html or direct translation of old API to new one in code of this method https://github.com/linq2db/linq2db/blob/master/Source/LinqToDB/Data/DataConnectionExtensions.LegacyMerge.cs.")]
public static Task<int> MergeAsync<T>(this ITable<T> table, IEnumerable<T> source, string? tableName = null, string? databaseName = null, string? schemaName = null, string? serverName = null, TableOptions tableOptions = TableOptions.NotSet, CancellationToken cancellationToken = default) where T : class
Parameters
tableITable<T>Target table.
sourceIEnumerable<T>Source data to merge into target table.
tableNamestringOptional target table name.
databaseNamestringOptional target table's database name.
schemaNamestringOptional target table's schema name.
serverNamestringOptional name of linked server. If not specified, value from mapping will be used.
tableOptionsTableOptionsTable options. See TableOptions enum for support information per provider.
cancellationTokenCancellationTokenOptional asynchronous operation cancellation token.
Returns
Type Parameters
TTarget table mapping class.
MergeAsync<T>(ITable<T>, Expression<Func<T, bool>>, IEnumerable<T>, string?, string?, string?, string?, TableOptions, CancellationToken)
Executes following merge operations asynchronously in specified order:
- Update
- Insert
- Delete By Source. Method could be used only with SQL Server.
[Obsolete("Legacy Merge API obsoleted and will be removed in future versions. See migration guide https://linq2db.github.io/articles/sql/merge/Merge-API-Migration.html or direct translation of old API to new one in code of this method https://github.com/linq2db/linq2db/blob/master/Source/LinqToDB/Data/DataConnectionExtensions.LegacyMerge.cs.")]
public static Task<int> MergeAsync<T>(this ITable<T> table, Expression<Func<T, bool>> predicate, IEnumerable<T> source, string? tableName = null, string? databaseName = null, string? schemaName = null, string? serverName = null, TableOptions tableOptions = TableOptions.NotSet, CancellationToken cancellationToken = default) where T : class
Parameters
tableITable<T>Target table.
predicateExpression<Func<T, bool>>Filter, applied to delete operation. Optional.
sourceIEnumerable<T>Source data to merge into target table.
tableNamestringOptional target table name.
databaseNamestringOptional target table's database name.
schemaNamestringOptional target table's schema name.
serverNamestringOptional name of linked server. If not specified, value from mapping will be used.
tableOptionsTableOptionsTable options. See TableOptions enum for support information per provider.
cancellationTokenCancellationTokenOptional asynchronous operation cancellation token.
Returns
Type Parameters
TTarget table mapping class.
MergeAsync<T>(ITable<T>, IQueryable<T>, Expression<Func<T, bool>>, string?, string?, string?, string?, TableOptions, CancellationToken)
Executes following merge operations asynchronously in specified order:
- Update
- Insert
- Delete By Source. Method could be used only with SQL Server.
[Obsolete("Legacy Merge API obsoleted and will be removed in future versions. See migration guide https://linq2db.github.io/articles/sql/merge/Merge-API-Migration.html or direct translation of old API to new one in code of this method https://github.com/linq2db/linq2db/blob/master/Source/LinqToDB/Data/DataConnectionExtensions.LegacyMerge.cs.")]
public static Task<int> MergeAsync<T>(this ITable<T> table, IQueryable<T> source, Expression<Func<T, bool>> predicate, string? tableName = null, string? databaseName = null, string? schemaName = null, string? serverName = null, TableOptions tableOptions = TableOptions.NotSet, CancellationToken cancellationToken = default) where T : class
Parameters
tableITable<T>Target table.
sourceIQueryable<T>Source data to merge into target table. All source data will be loaded from server for command generation.
predicateExpression<Func<T, bool>>Filter, applied both to source and delete operation. Required.
tableNamestringOptional target table name.
databaseNamestringOptional target table's database name.
schemaNamestringOptional target table's schema name.
serverNamestringOptional name of linked server. If not specified, value from mapping will be used.
tableOptionsTableOptionsTable options. See TableOptions enum for support information per provider.
cancellationTokenCancellationTokenOptional asynchronous operation cancellation token.
Returns
Type Parameters
TTarget table mapping class.
Merge<T>(DataConnection, bool, IEnumerable<T>, string?, string?, string?, string?, TableOptions)
Executes following merge operations in specified order:
- Update
- Insert
- Delete By Source (optional).
If delete operation enabled by
deleteparameter - method could be used only for with Server.
[Obsolete("Legacy Merge API obsoleted and will be removed in future versions. See migration guide https://linq2db.github.io/articles/sql/merge/Merge-API-Migration.html or direct translation of old API to new one in code of this method https://github.com/linq2db/linq2db/blob/master/Source/LinqToDB/Data/DataConnectionExtensions.LegacyMerge.cs.")]
public static int Merge<T>(this DataConnection dataConnection, bool delete, IEnumerable<T> source, string? tableName = null, string? databaseName = null, string? schemaName = null, string? serverName = null, TableOptions tableOptions = TableOptions.NotSet) where T : class
Parameters
dataConnectionDataConnectionData connection instance.
deleteboolIf true, merge command will include delete by source operation without condition.
sourceIEnumerable<T>Source data to merge into target table.
tableNamestringOptional target table name.
databaseNamestringOptional target table's database name.
schemaNamestringOptional target table's schema name.
serverNamestringOptional name of linked server. If not specified, value from mapping will be used.
tableOptionsTableOptionsTable options. See TableOptions enum for support information per provider.
Returns
- int
Returns number of affected target records.
Type Parameters
TTarget table mapping class.
Merge<T>(DataConnection, IEnumerable<T>, string?, string?, string?, string?, TableOptions)
Executes following merge operations in specified order:
- Update
- Insert.
[Obsolete("Legacy Merge API obsoleted and will be removed in future versions. See migration guide https://linq2db.github.io/articles/sql/merge/Merge-API-Migration.html or direct translation of old API to new one in code of this method https://github.com/linq2db/linq2db/blob/master/Source/LinqToDB/Data/DataConnectionExtensions.LegacyMerge.cs.")]
public static int Merge<T>(this DataConnection dataConnection, IEnumerable<T> source, string? tableName = null, string? databaseName = null, string? schemaName = null, string? serverName = null, TableOptions tableOptions = TableOptions.NotSet) where T : class
Parameters
dataConnectionDataConnectionData connection instance.
sourceIEnumerable<T>Source data to merge into target table.
tableNamestringOptional target table name.
databaseNamestringOptional target table's database name.
schemaNamestringOptional target table's schema name.
serverNamestringOptional name of linked server. If not specified, value from mapping will be used.
tableOptionsTableOptionsTable options. See TableOptions enum for support information per provider.
Returns
- int
Returns number of affected target records.
Type Parameters
TTarget table mapping class.
Merge<T>(DataConnection, Expression<Func<T, bool>>, IEnumerable<T>, string?, string?, string?, string?, TableOptions)
Executes following merge operations in specified order:
- Update
- Insert
- Delete By Source. Method could be used only with SQL Server.
[Obsolete("Legacy Merge API obsoleted and will be removed in future versions. See migration guide https://linq2db.github.io/articles/sql/merge/Merge-API-Migration.html or direct translation of old API to new one in code of this method https://github.com/linq2db/linq2db/blob/master/Source/LinqToDB/Data/DataConnectionExtensions.LegacyMerge.cs.")]
public static int Merge<T>(this DataConnection dataConnection, Expression<Func<T, bool>> predicate, IEnumerable<T> source, string? tableName = null, string? databaseName = null, string? schemaName = null, string? serverName = null, TableOptions tableOptions = TableOptions.NotSet) where T : class
Parameters
dataConnectionDataConnectionData connection instance.
predicateExpression<Func<T, bool>>Filter, applied to delete operation. Optional.
sourceIEnumerable<T>Source data to merge into target table.
tableNamestringOptional target table name.
databaseNamestringOptional target table's database name.
schemaNamestringOptional target table's schema name.
serverNamestringOptional name of linked server. If not specified, value from mapping will be used.
tableOptionsTableOptionsTable options. See TableOptions enum for support information per provider.
Returns
- int
Returns number of affected target records.
Type Parameters
TTarget table mapping class.
Merge<T>(DataConnection, IQueryable<T>, Expression<Func<T, bool>>, string?, string?, string?, string?, TableOptions)
Executes following merge operations in specified order:
- Update
- Insert
- Delete By Source. Method could be used only with SQL Server.
[Obsolete("Legacy Merge API obsoleted and will be removed in future versions. See migration guide https://linq2db.github.io/articles/sql/merge/Merge-API-Migration.html or direct translation of old API to new one in code of this method https://github.com/linq2db/linq2db/blob/master/Source/LinqToDB/Data/DataConnectionExtensions.LegacyMerge.cs.")]
public static int Merge<T>(this DataConnection dataConnection, IQueryable<T> source, Expression<Func<T, bool>> predicate, string? tableName = null, string? databaseName = null, string? schemaName = null, string? serverName = null, TableOptions tableOptions = TableOptions.NotSet) where T : class
Parameters
dataConnectionDataConnectionData connection instance.
sourceIQueryable<T>Source data to merge into target table. All source data will be loaded from server for command generation.
predicateExpression<Func<T, bool>>Filter, applied both to source and delete operation. Required.
tableNamestringOptional target table name.
databaseNamestringOptional target table's database name.
schemaNamestringOptional target table's schema name.
serverNamestringOptional name of linked server. If not specified, value from mapping will be used.
tableOptionsTableOptionsTable options. See TableOptions enum for support information per provider.
Returns
- int
Returns number of affected target records.
Type Parameters
TTarget table mapping class.
Merge<T>(ITable<T>, bool, IEnumerable<T>, string?, string?, string?, string?, TableOptions)
Executes following merge operations in specified order:
- Update
- Insert
- Delete By Source (optional).
If delete operation enabled by
deleteparameter - method could be used only with SQL Server.
[Obsolete("Legacy Merge API obsoleted and will be removed in future versions. See migration guide https://linq2db.github.io/articles/sql/merge/Merge-API-Migration.html or direct translation of old API to new one in code of this method https://github.com/linq2db/linq2db/blob/master/Source/LinqToDB/Data/DataConnectionExtensions.LegacyMerge.cs.")]
public static int Merge<T>(this ITable<T> table, bool delete, IEnumerable<T> source, string? tableName = null, string? databaseName = null, string? schemaName = null, string? serverName = null, TableOptions tableOptions = TableOptions.NotSet) where T : class
Parameters
tableITable<T>Target table.
deleteboolIf true, merge command will include delete by source operation without condition.
sourceIEnumerable<T>Source data to merge into target table.
tableNamestringOptional target table name.
databaseNamestringOptional target table's database name.
schemaNamestringOptional target table's schema name.
serverNamestringOptional name of linked server. If not specified, value from mapping will be used.
tableOptionsTableOptionsTable options. See TableOptions enum for support information per provider.
Returns
- int
Returns number of affected target records.
Type Parameters
TTarget table mapping class.
Merge<T>(ITable<T>, IEnumerable<T>, string?, string?, string?, string?, TableOptions)
Executes following merge operations in specified order:
- Update
- Insert.
[Obsolete("Legacy Merge API obsoleted and will be removed in future versions. See migration guide https://linq2db.github.io/articles/sql/merge/Merge-API-Migration.html or direct translation of old API to new one in code of this method https://github.com/linq2db/linq2db/blob/master/Source/LinqToDB/Data/DataConnectionExtensions.LegacyMerge.cs.")]
public static int Merge<T>(this ITable<T> table, IEnumerable<T> source, string? tableName = null, string? databaseName = null, string? schemaName = null, string? serverName = null, TableOptions tableOptions = TableOptions.NotSet) where T : class
Parameters
tableITable<T>Target table.
sourceIEnumerable<T>Source data to merge into target table.
tableNamestringOptional target table name.
databaseNamestringOptional target table's database name.
schemaNamestringOptional target table's schema name.
serverNamestringOptional name of linked server. If not specified, value from mapping will be used.
tableOptionsTableOptionsTable options. See TableOptions enum for support information per provider.
Returns
- int
Returns number of affected target records.
Type Parameters
TTarget table mapping class.
Merge<T>(ITable<T>, Expression<Func<T, bool>>, IEnumerable<T>, string?, string?, string?, string?, TableOptions)
Executes following merge operations in specified order:
- Update
- Insert
- Delete By Source. Method could be used only with SQL Server.
[Obsolete("Legacy Merge API obsoleted and will be removed in future versions. See migration guide https://linq2db.github.io/articles/sql/merge/Merge-API-Migration.html or direct translation of old API to new one in code of this method https://github.com/linq2db/linq2db/blob/master/Source/LinqToDB/Data/DataConnectionExtensions.LegacyMerge.cs.")]
public static int Merge<T>(this ITable<T> table, Expression<Func<T, bool>> predicate, IEnumerable<T> source, string? tableName = null, string? databaseName = null, string? schemaName = null, string? serverName = null, TableOptions tableOptions = TableOptions.NotSet) where T : class
Parameters
tableITable<T>Target table.
predicateExpression<Func<T, bool>>Filter, applied to delete operation. Optional.
sourceIEnumerable<T>Source data to merge into target table.
tableNamestringOptional target table name.
databaseNamestringOptional target table's database name.
schemaNamestringOptional target table's schema name.
serverNamestringOptional name of linked server. If not specified, value from mapping will be used.
tableOptionsTableOptionsTable options. See TableOptions enum for support information per provider.
Returns
- int
Returns number of affected target records.
Type Parameters
TTarget table mapping class.
Merge<T>(ITable<T>, IQueryable<T>, Expression<Func<T, bool>>, string?, string?, string?, string?, TableOptions)
Executes following merge operations in specified order:
- Update
- Insert
- Delete By Source. Method could be used only with SQL Server.
[Obsolete("Legacy Merge API obsoleted and will be removed in future versions. See migration guide https://linq2db.github.io/articles/sql/merge/Merge-API-Migration.html or direct translation of old API to new one in code of this method https://github.com/linq2db/linq2db/blob/master/Source/LinqToDB/Data/DataConnectionExtensions.LegacyMerge.cs.")]
public static int Merge<T>(this ITable<T> table, IQueryable<T> source, Expression<Func<T, bool>> predicate, string? tableName = null, string? databaseName = null, string? schemaName = null, string? serverName = null, TableOptions tableOptions = TableOptions.NotSet) where T : class
Parameters
tableITable<T>Target table.
sourceIQueryable<T>Source data to merge into target table. All source data will be loaded from server for command generation.
predicateExpression<Func<T, bool>>Filter, applied both to source and delete operation. Required.
tableNamestringOptional target table name.
databaseNamestringOptional target table's database name.
schemaNamestringOptional target table's schema name.
serverNamestringOptional name of linked server. If not specified, value from mapping will be used.
tableOptionsTableOptionsTable options. See TableOptions enum for support information per provider.
Returns
- int
Returns number of affected target records.
Type Parameters
TTarget table mapping class.
QueryMultipleAsync<T>(DataConnection, string, params DataParameter[])
Executes command asynchronously and returns a result containing multiple result sets.
public static Task<T> QueryMultipleAsync<T>(this DataConnection connection, string sql, params DataParameter[] parameters) where T : class
Parameters
connectionDataConnectionDatabase connection.
sqlstringCommand text.
parametersDataParameter[]Command parameters.
Returns
- Task<T>
A task that represents the asynchronous operation. The task result contains object with multiply result sets.
Type Parameters
TResult set type.
Examples
Example of T definition with ResultSetIndexAttribute.
class MultipleResult
{
[ResultSetIndex(0)] public IEnumerable<Person> AllPersons { get; set; }
[ResultSetIndex(1)] public IList<Doctor> AllDoctors { get; set; }
[ResultSetIndex(2)] public IEnumerable<Patient> AllPatients { get; set; }
[ResultSetIndex(3)] public Patient FirstPatient { get; set; }
}
Example of T definition without attributes.
class MultipleResult
{
public IEnumerable<Person> AllPersons { get; set; }
public IList<Doctor> AllDoctors { get; set; }
public IEnumerable<Patient> AllPatients { get; set; }
public Patient FirstPatient { get; set; }
}
Remarks
- type
Tshould have default constructor. - if at least one property or field has ResultSetIndexAttribute, then properties that are not marked with ResultSetIndexAttribute will be ignored.
- if there is missing index in properties that are marked with ResultSetIndexAttribute, then result set under missing index will be ignored.
- if there is no ResultSetIndexAttribute, then all non readonly fields or properties with setter will read from multiple result set. Order is based on their appearance in class.
QueryMultipleAsync<T>(DataConnection, string, CancellationToken, params DataParameter[])
Executes command asynchronously and returns a result containing multiple result sets.
public static Task<T> QueryMultipleAsync<T>(this DataConnection connection, string sql, CancellationToken cancellationToken, params DataParameter[] parameters) where T : class
Parameters
connectionDataConnectionDatabase connection.
sqlstringCommand text.
cancellationTokenCancellationTokenAsynchronous operation cancellation token.
parametersDataParameter[]Command parameters.
Returns
- Task<T>
A task that represents the asynchronous operation. The task result contains object with multiply result sets.
Type Parameters
TResult set type.
Examples
Example of T definition with ResultSetIndexAttribute.
class MultipleResult
{
[ResultSetIndex(0)] public IEnumerable<Person> AllPersons { get; set; }
[ResultSetIndex(1)] public IList<Doctor> AllDoctors { get; set; }
[ResultSetIndex(2)] public IEnumerable<Patient> AllPatients { get; set; }
[ResultSetIndex(3)] public Patient FirstPatient { get; set; }
}
Example of T definition without attributes.
class MultipleResult
{
public IEnumerable<Person> AllPersons { get; set; }
public IList<Doctor> AllDoctors { get; set; }
public IEnumerable<Patient> AllPatients { get; set; }
public Patient FirstPatient { get; set; }
}
Remarks
- type
Tshould have default constructor. - if at least one property or field has ResultSetIndexAttribute, then properties that are not marked with ResultSetIndexAttribute will be ignored.
- if there is missing index in properties that are marked with ResultSetIndexAttribute, then result set under missing index will be ignored.
- if there is no ResultSetIndexAttribute, then all non readonly fields or properties with setter will read from multiple result set. Order is based on their appearance in class.
QueryMultiple<T>(DataConnection, string, params DataParameter[])
Executes command and returns a result containing multiple result sets.
public static T QueryMultiple<T>(this DataConnection connection, string sql, params DataParameter[] parameters) where T : class
Parameters
connectionDataConnectionDatabase connection.
sqlstringCommand text.
parametersDataParameter[]Command parameters.
Returns
- T
Returns result.
Type Parameters
TResult set type.
Examples
Example of T definition with ResultSetIndexAttribute.
class MultipleResult
{
[ResultSetIndex(0)] public IEnumerable<Person> AllPersons { get; set; }
[ResultSetIndex(1)] public IList<Doctor> AllDoctors { get; set; }
[ResultSetIndex(2)] public IEnumerable<Patient> AllPatients { get; set; }
[ResultSetIndex(3)] public Patient FirstPatient { get; set; }
}
Example of T definition without attributes.
class MultipleResult
{
public IEnumerable<Person> AllPersons { get; set; }
public IList<Doctor> AllDoctors { get; set; }
public IEnumerable<Patient> AllPatients { get; set; }
public Patient FirstPatient { get; set; }
}
Remarks
- type
Tshould have default constructor. - if at least one property or field has ResultSetIndexAttribute, then properties that are not marked with ResultSetIndexAttribute will be ignored.
- if there is missing index in properties that are marked with ResultSetIndexAttribute, then result set under missing index will be ignored.
- if there is no ResultSetIndexAttribute, then all non readonly fields or properties with setter will read from multiple result set. Order is based on their appearance in class.
QueryProcAsync<T>(DataConnection, Func<DbDataReader, T>, string, params DataParameter[])
Executes command asynchronously using StoredProcedure command type and returns results as collection of values, mapped using provided mapping function.
public static Task<IEnumerable<T>> QueryProcAsync<T>(this DataConnection connection, Func<DbDataReader, T> objectReader, string sql, params DataParameter[] parameters)
Parameters
connectionDataConnectionDatabase connection.
objectReaderFunc<DbDataReader, T>Record mapping function from data reader.
sqlstringCommand text. This is caller's responsibility to properly escape procedure name.
parametersDataParameter[]Command parameters.
Returns
- Task<IEnumerable<T>>
Returns collection of query result records.
Type Parameters
TResult record type.
QueryProcAsync<T>(DataConnection, Func<DbDataReader, T>, string, object?, CancellationToken)
Executes command asynchronously using StoredProcedure command type and returns results as collection of values, mapped using provided mapping function.
public static Task<IEnumerable<T>> QueryProcAsync<T>(this DataConnection connection, Func<DbDataReader, T> objectReader, string sql, object? parameters, CancellationToken cancellationToken = default)
Parameters
connectionDataConnectionDatabase connection.
objectReaderFunc<DbDataReader, T>Record mapping function from data reader.
sqlstringCommand text. This is caller's responsibility to properly escape procedure name.
parametersobjectCommand parameters. Supported values:
-
nullfor command without parameters;- single DataParameter instance;
- array of DataParameter parameters;
- mapping class entity.
Last case will convert all mapped columns to DataParameter instances using following logic:
- if column is of DataParameter type, column value will be used. If parameter name (Name) is not set, column name will be used;
- if converter from column type to DataParameter is defined in mapping schema, it will be used to create parameter with column name passed to converter;
- otherwise column value will be converted to DataParameter using column name as parameter name and column value will be converted to parameter value using conversion, defined by mapping schema.
cancellationTokenCancellationTokenAsynchronous operation cancellation token.
Returns
- Task<IEnumerable<T>>
Returns collection of query result records.
Type Parameters
TResult record type.
QueryProcAsync<T>(DataConnection, Func<DbDataReader, T>, string, CancellationToken, params DataParameter[])
Executes command asynchronously using StoredProcedure command type and returns results as collection of values, mapped using provided mapping function.
public static Task<IEnumerable<T>> QueryProcAsync<T>(this DataConnection connection, Func<DbDataReader, T> objectReader, string sql, CancellationToken cancellationToken, params DataParameter[] parameters)
Parameters
connectionDataConnectionDatabase connection.
objectReaderFunc<DbDataReader, T>Record mapping function from data reader.
sqlstringCommand text. This is caller's responsibility to properly escape procedure name.
cancellationTokenCancellationTokenAsynchronous operation cancellation token.
parametersDataParameter[]Command parameters.
Returns
- Task<IEnumerable<T>>
Returns collection of query result records.
Type Parameters
TResult record type.
QueryProcAsync<T>(DataConnection, string, params DataParameter[])
Executes command using StoredProcedure command type and returns results as collection of values of specified type.
public static Task<IEnumerable<T>> QueryProcAsync<T>(this DataConnection connection, string sql, params DataParameter[] parameters)
Parameters
connectionDataConnectionDatabase connection.
sqlstringCommand text. This is caller's responsibility to properly escape procedure name.
parametersDataParameter[]Command parameters.
Returns
- Task<IEnumerable<T>>
Returns collection of query result records.
Type Parameters
TResult record type.
QueryProcAsync<T>(DataConnection, string, object?, CancellationToken)
Executes command asynchronously using StoredProcedure command type and returns results as collection of values of specified type.
public static Task<IEnumerable<T>> QueryProcAsync<T>(this DataConnection connection, string sql, object? parameters, CancellationToken cancellationToken = default)
Parameters
connectionDataConnectionDatabase connection.
sqlstringCommand text. This is caller's responsibility to properly escape procedure name.
parametersobjectCommand parameters. Supported values:
-
nullfor command without parameters;- single DataParameter instance;
- array of DataParameter parameters;
- mapping class entity.
Last case will convert all mapped columns to DataParameter instances using following logic:
- if column is of DataParameter type, column value will be used. If parameter name (Name) is not set, column name will be used;
- if converter from column type to DataParameter is defined in mapping schema, it will be used to create parameter with column name passed to converter;
- otherwise column value will be converted to DataParameter using column name as parameter name and column value will be converted to parameter value using conversion, defined by mapping schema.
cancellationTokenCancellationTokenAsynchronous operation cancellation token.
Returns
- Task<IEnumerable<T>>
Returns collection of query result records.
Type Parameters
TResult record type.
QueryProcAsync<T>(DataConnection, string, CancellationToken, params DataParameter[])
Executes command using StoredProcedure command type and returns results as collection of values of specified type.
public static Task<IEnumerable<T>> QueryProcAsync<T>(this DataConnection connection, string sql, CancellationToken cancellationToken, params DataParameter[] parameters)
Parameters
connectionDataConnectionDatabase connection.
sqlstringCommand text. This is caller's responsibility to properly escape procedure name.
cancellationTokenCancellationTokenAsynchronous operation cancellation token.
parametersDataParameter[]Command parameters.
Returns
- Task<IEnumerable<T>>
Returns collection of query result records.
Type Parameters
TResult record type.
QueryProcAsync<T>(DataConnection, T, string, params DataParameter[])
Executes stored procedure asynchronously and returns results as collection of values of specified type.
public static Task<IEnumerable<T>> QueryProcAsync<T>(this DataConnection connection, T template, string sql, params DataParameter[] parameters)
Parameters
connectionDataConnectionDatabase connection.
templateTThis value used only for
Tparameter type inference, which makes this method usable with anonymous types.sqlstringCommand text.
parametersDataParameter[]Command parameters.
Returns
- Task<IEnumerable<T>>
Returns collection of query result records.
Type Parameters
TResult record type.
QueryProcAsync<T>(DataConnection, T, string, object?, CancellationToken)
Executes stored procedure asynchronously and returns results as collection of values of specified type.
public static Task<IEnumerable<T>> QueryProcAsync<T>(this DataConnection connection, T template, string sql, object? parameters, CancellationToken cancellationToken = default)
Parameters
connectionDataConnectionDatabase connection.
templateTThis value used only for
Tparameter type inference, which makes this method usable with anonymous types.sqlstringCommand text.
parametersobjectCommand parameters. Supported values:
-
nullfor command without parameters;- single DataParameter instance;
- array of DataParameter parameters;
- mapping class entity.
Last case will convert all mapped columns to DataParameter instances using following logic:
- if column is of DataParameter type, column value will be used. If parameter name (Name) is not set, column name will be used;
- if converter from column type to DataParameter is defined in mapping schema, it will be used to create parameter with column name passed to converter;
- otherwise column value will be converted to DataParameter using column name as parameter name and column value will be converted to parameter value using conversion, defined by mapping schema.
cancellationTokenCancellationTokenAsynchronous operation cancellation token.
Returns
- Task<IEnumerable<T>>
Returns collection of query result records.
Type Parameters
TResult record type.
QueryProcAsync<T>(DataConnection, T, string, CancellationToken, params DataParameter[])
Executes stored procedure asynchronously and returns results as collection of values of specified type.
public static Task<IEnumerable<T>> QueryProcAsync<T>(this DataConnection connection, T template, string sql, CancellationToken cancellationToken, params DataParameter[] parameters)
Parameters
connectionDataConnectionDatabase connection.
templateTThis value used only for
Tparameter type inference, which makes this method usable with anonymous types.sqlstringCommand text.
cancellationTokenCancellationTokenAsynchronous operation cancellation token.
parametersDataParameter[]Command parameters.
Returns
- Task<IEnumerable<T>>
Returns collection of query result records.
Type Parameters
TResult record type.
QueryProcMultipleAsync<T>(DataConnection, string, params DataParameter[])
Executes command asynchronously using StoredProcedure command type and returns a result containing multiple result sets.
Sets result values for output and reference parameters to corresponding parameters in parameters.
public static Task<T> QueryProcMultipleAsync<T>(this DataConnection connection, string sql, params DataParameter[] parameters) where T : class
Parameters
connectionDataConnectionDatabase connection.
sqlstringCommand text. This is caller's responsibility to properly escape procedure name.
parametersDataParameter[]Command parameters.
Returns
- Task<T>
A task that represents the asynchronous operation. The task result contains object with multiply result sets.
Type Parameters
TResult set type.
Examples
Example of T definition with ResultSetIndexAttribute.
class MultipleResult
{
[ResultSetIndex(0)] public IEnumerable<Person> AllPersons { get; set; }
[ResultSetIndex(1)] public IList<Doctor> AllDoctors { get; set; }
[ResultSetIndex(2)] public IEnumerable<Patient> AllPatients { get; set; }
[ResultSetIndex(3)] public Patient FirstPatient { get; set; }
}
Example of T definition without attributes.
class MultipleResult
{
public IEnumerable<Person> AllPersons { get; set; }
public IList<Doctor> AllDoctors { get; set; }
public IEnumerable<Patient> AllPatients { get; set; }
public Patient FirstPatient { get; set; }
}
Remarks
- type
Tshould have default constructor. - if at least one property or field has ResultSetIndexAttribute, then properties that are not marked with ResultSetIndexAttribute will be ignored.
- if there is missing index in properties that are marked with ResultSetIndexAttribute, then result set under missing index will be ignored.
- if there is no ResultSetIndexAttribute, then all non readonly fields or properties with setter will read from multiple result set. Order is based on their appearance in class.
QueryProcMultipleAsync<T>(DataConnection, string, object?)
Executes command asynchronously using StoredProcedure command type and returns a result containing multiple result sets.
public static Task<T> QueryProcMultipleAsync<T>(this DataConnection connection, string sql, object? parameters) where T : class
Parameters
connectionDataConnectionDatabase connection.
sqlstringCommand text. This is caller's responsibility to properly escape procedure name.
parametersobjectCommand parameters. Supported values:
-
nullfor command without parameters;- single DataParameter instance;
- array of DataParameter parameters;
- mapping class entity.
Last case will convert all mapped columns to DataParameter instances using following logic:
- if column is of DataParameter type, column value will be used. If parameter name (Name) is not set, column name will be used;
- if converter from column type to DataParameter is defined in mapping schema, it will be used to create parameter with column name passed to converter;
- otherwise column value will be converted to DataParameter using column name as parameter name and column value will be converted to parameter value using conversion, defined by mapping schema.
Returns
- Task<T>
A task that represents the asynchronous operation. The task result contains object with multiply result sets.
Type Parameters
TResult set type.
Examples
Example of T definition with ResultSetIndexAttribute.
class MultipleResult
{
[ResultSetIndex(0)] public IEnumerable<Person> AllPersons { get; set; }
[ResultSetIndex(1)] public IList<Doctor> AllDoctors { get; set; }
[ResultSetIndex(2)] public IEnumerable<Patient> AllPatients { get; set; }
[ResultSetIndex(3)] public Patient FirstPatient { get; set; }
}
Example of T definition without attributes.
class MultipleResult
{
public IEnumerable<Person> AllPersons { get; set; }
public IList<Doctor> AllDoctors { get; set; }
public IEnumerable<Patient> AllPatients { get; set; }
public Patient FirstPatient { get; set; }
}
Remarks
- type
Tshould have default constructor. - if at least one property or field has ResultSetIndexAttribute, then properties that are not marked with ResultSetIndexAttribute will be ignored.
- if there is missing index in properties that are marked with ResultSetIndexAttribute, then result set under missing index will be ignored.
- if there is no ResultSetIndexAttribute, then all non readonly fields or properties with setter will read from multiple result set. Order is based on their appearance in class.
QueryProcMultipleAsync<T>(DataConnection, string, CancellationToken, params DataParameter[])
Executes command asynchronously using StoredProcedure command type and returns a result containing multiple result sets.
public static Task<T> QueryProcMultipleAsync<T>(this DataConnection connection, string sql, CancellationToken cancellationToken, params DataParameter[] parameters) where T : class
Parameters
connectionDataConnectionDatabase connection.
sqlstringCommand text. This is caller's responsibility to properly escape procedure name.
cancellationTokenCancellationTokenAsynchronous operation cancellation token.
parametersDataParameter[]Command parameters.
Returns
- Task<T>
A task that represents the asynchronous operation. The task result contains object with multiply result sets.
Type Parameters
TResult set type.
Examples
Example of T definition with ResultSetIndexAttribute.
class MultipleResult
{
[ResultSetIndex(0)] public IEnumerable<Person> AllPersons { get; set; }
[ResultSetIndex(1)] public IList<Doctor> AllDoctors { get; set; }
[ResultSetIndex(2)] public IEnumerable<Patient> AllPatients { get; set; }
[ResultSetIndex(3)] public Patient FirstPatient { get; set; }
}
Example of T definition without attributes.
class MultipleResult
{
public IEnumerable<Person> AllPersons { get; set; }
public IList<Doctor> AllDoctors { get; set; }
public IEnumerable<Patient> AllPatients { get; set; }
public Patient FirstPatient { get; set; }
}
Remarks
- type
Tshould have default constructor. - if at least one property or field has ResultSetIndexAttribute, then properties that are not marked with ResultSetIndexAttribute will be ignored.
- if there is missing index in properties that are marked with ResultSetIndexAttribute, then result set under missing index will be ignored.
- if there is no ResultSetIndexAttribute, then all non readonly fields or properties with setter will read from multiple result set. Order is based on their appearance in class.
QueryProcMultipleAsync<T>(DataConnection, string, CancellationToken, object?)
Executes command asynchronously using StoredProcedure command type and returns a result containing multiple result sets.
public static Task<T> QueryProcMultipleAsync<T>(this DataConnection connection, string sql, CancellationToken cancellationToken, object? parameters) where T : class
Parameters
connectionDataConnectionDatabase connection.
sqlstringCommand text. This is caller's responsibility to properly escape procedure name.
cancellationTokenCancellationTokenAsynchronous operation cancellation token.
parametersobjectCommand parameters. Supported values:
-
nullfor command without parameters;- single DataParameter instance;
- array of DataParameter parameters;
- mapping class entity.
Last case will convert all mapped columns to DataParameter instances using following logic:
- if column is of DataParameter type, column value will be used. If parameter name (Name) is not set, column name will be used;
- if converter from column type to DataParameter is defined in mapping schema, it will be used to create parameter with column name passed to converter;
- otherwise column value will be converted to DataParameter using column name as parameter name and column value will be converted to parameter value using conversion, defined by mapping schema.
Returns
- Task<T>
A task that represents the asynchronous operation. The task result contains object with multiply result sets.
Type Parameters
TResult set type.
Examples
Example of T definition with ResultSetIndexAttribute.
class MultipleResult
{
[ResultSetIndex(0)] public IEnumerable<Person> AllPersons { get; set; }
[ResultSetIndex(1)] public IList<Doctor> AllDoctors { get; set; }
[ResultSetIndex(2)] public IEnumerable<Patient> AllPatients { get; set; }
[ResultSetIndex(3)] public Patient FirstPatient { get; set; }
}
Example of T definition without attributes.
class MultipleResult
{
public IEnumerable<Person> AllPersons { get; set; }
public IList<Doctor> AllDoctors { get; set; }
public IEnumerable<Patient> AllPatients { get; set; }
public Patient FirstPatient { get; set; }
}
Remarks
- type
Tshould have default constructor. - if at least one property or field has ResultSetIndexAttribute, then properties that are not marked with ResultSetIndexAttribute will be ignored.
- if there is missing index in properties that are marked with ResultSetIndexAttribute, then result set under missing index will be ignored.
- if there is no ResultSetIndexAttribute, then all non readonly fields or properties with setter will read from multiple result set. Order is based on their appearance in class.
QueryProcMultiple<T>(DataConnection, string, params DataParameter[])
Executes command using StoredProcedure command type and returns a result containing multiple result sets.
Sets result values for output and reference parameters to corresponding parameters in parameters.
public static T QueryProcMultiple<T>(this DataConnection connection, string sql, params DataParameter[] parameters) where T : class
Parameters
connectionDataConnectionDatabase connection.
sqlstringCommand text. This is caller's responsibility to properly escape procedure name.
parametersDataParameter[]Command parameters.
Returns
- T
Returns result.
Type Parameters
TResult set type.
Examples
Example of T definition with ResultSetIndexAttribute.
class MultipleResult
{
[ResultSetIndex(0)] public IEnumerable<Person> AllPersons { get; set; }
[ResultSetIndex(1)] public IList<Doctor> AllDoctors { get; set; }
[ResultSetIndex(2)] public IEnumerable<Patient> AllPatients { get; set; }
[ResultSetIndex(3)] public Patient FirstPatient { get; set; }
}
Example of T definition without attributes.
class MultipleResult
{
public IEnumerable<Person> AllPersons { get; set; }
public IList<Doctor> AllDoctors { get; set; }
public IEnumerable<Patient> AllPatients { get; set; }
public Patient FirstPatient { get; set; }
}
Remarks
- type
Tshould have default constructor. - if at least one property or field has ResultSetIndexAttribute, then properties that are not marked with ResultSetIndexAttribute will be ignored.
- if there is missing index in properties that are marked with ResultSetIndexAttribute, then result set under missing index will be ignored.
- if there is no ResultSetIndexAttribute, then all non readonly fields or properties with setter will read from multiple result set. Order is based on their appearance in class.
QueryProcMultiple<T>(DataConnection, string, object?)
Executes command using StoredProcedure command type and returns a result containing multiple result sets.
public static T QueryProcMultiple<T>(this DataConnection connection, string sql, object? parameters) where T : class
Parameters
connectionDataConnectionDatabase connection.
sqlstringCommand text. This is caller's responsibility to properly escape procedure name.
parametersobjectCommand parameters. Supported values:
-
nullfor command without parameters;- single DataParameter instance;
- array of DataParameter parameters;
- mapping class entity.
Last case will convert all mapped columns to DataParameter instances using following logic:
- if column is of DataParameter type, column value will be used. If parameter name (Name) is not set, column name will be used;
- if converter from column type to DataParameter is defined in mapping schema, it will be used to create parameter with column name passed to converter;
- otherwise column value will be converted to DataParameter using column name as parameter name and column value will be converted to parameter value using conversion, defined by mapping schema.
Returns
- T
Returns result.
Type Parameters
TResult set type.
Examples
Example of T definition with ResultSetIndexAttribute.
class MultipleResult
{
[ResultSetIndex(0)] public IEnumerable<Person> AllPersons { get; set; }
[ResultSetIndex(1)] public IList<Doctor> AllDoctors { get; set; }
[ResultSetIndex(2)] public IEnumerable<Patient> AllPatients { get; set; }
[ResultSetIndex(3)] public Patient FirstPatient { get; set; }
}
Example of T definition without attributes.
class MultipleResult
{
public IEnumerable<Person> AllPersons { get; set; }
public IList<Doctor> AllDoctors { get; set; }
public IEnumerable<Patient> AllPatients { get; set; }
public Patient FirstPatient { get; set; }
}
Remarks
- type
Tshould have default constructor. - if at least one property or field has ResultSetIndexAttribute, then properties that are not marked with ResultSetIndexAttribute will be ignored.
- if there is missing index in properties that are marked with ResultSetIndexAttribute, then result set under missing index will be ignored.
- if there is no ResultSetIndexAttribute, then all non readonly fields or properties with setter will read from multiple result set. Order is based on their appearance in class.
QueryProc<T>(DataConnection, Func<DbDataReader, T>, string, params DataParameter[])
Executes command using StoredProcedure command type and returns results as collection of values, mapped using provided mapping function.
public static IEnumerable<T> QueryProc<T>(this DataConnection connection, Func<DbDataReader, T> objectReader, string sql, params DataParameter[] parameters)
Parameters
connectionDataConnectionDatabase connection.
objectReaderFunc<DbDataReader, T>Record mapping function from data reader.
sqlstringCommand text. This is caller's responsibility to properly escape procedure name.
parametersDataParameter[]Command parameters.
Returns
- IEnumerable<T>
Returns collection of query result records.
Type Parameters
TResult record type.
QueryProc<T>(DataConnection, Func<DbDataReader, T>, string, object?)
Executes command using StoredProcedure command type and returns results as collection of values, mapped using provided mapping function.
public static IEnumerable<T> QueryProc<T>(this DataConnection connection, Func<DbDataReader, T> objectReader, string sql, object? parameters)
Parameters
connectionDataConnectionDatabase connection.
objectReaderFunc<DbDataReader, T>Record mapping function from data reader.
sqlstringCommand text. This is caller's responsibility to properly escape procedure name.
parametersobjectCommand parameters. Supported values:
-
nullfor command without parameters;- single DataParameter instance;
- array of DataParameter parameters;
- mapping class entity.
Last case will convert all mapped columns to DataParameter instances using following logic:
- if column is of DataParameter type, column value will be used. If parameter name (Name) is not set, column name will be used;
- if converter from column type to DataParameter is defined in mapping schema, it will be used to create parameter with column name passed to converter;
- otherwise column value will be converted to DataParameter using column name as parameter name and column value will be converted to parameter value using conversion, defined by mapping schema.
Returns
- IEnumerable<T>
Returns collection of query result records.
Type Parameters
TResult record type.
QueryProc<T>(DataConnection, string, params DataParameter[])
Executes command using StoredProcedure command type and returns results as collection of values of specified type.
public static IEnumerable<T> QueryProc<T>(this DataConnection connection, string sql, params DataParameter[] parameters)
Parameters
connectionDataConnectionDatabase connection.
sqlstringCommand text. This is caller's responsibility to properly escape procedure name.
parametersDataParameter[]Command parameters.
Returns
- IEnumerable<T>
Returns collection of query result records.
Type Parameters
TResult record type.
QueryProc<T>(DataConnection, string, object?)
Executes command using StoredProcedure command type and returns results as collection of values of specified type.
public static IEnumerable<T> QueryProc<T>(this DataConnection connection, string sql, object? parameters)
Parameters
connectionDataConnectionDatabase connection.
sqlstringCommand text. This is caller's responsibility to properly escape procedure name.
parametersobjectCommand parameters. Supported values:
-
nullfor command without parameters;- single DataParameter instance;
- array of DataParameter parameters;
- mapping class entity.
Last case will convert all mapped columns to DataParameter instances using following logic:
- if column is of DataParameter type, column value will be used. If parameter name (Name) is not set, column name will be used;
- if converter from column type to DataParameter is defined in mapping schema, it will be used to create parameter with column name passed to converter;
- otherwise column value will be converted to DataParameter using column name as parameter name and column value will be converted to parameter value using conversion, defined by mapping schema.
Returns
- IEnumerable<T>
Returns collection of query result records.
Type Parameters
TResult record type.
QueryProc<T>(DataConnection, T, string, params DataParameter[])
Executes stored procedure and returns results as collection of values of specified type.
public static IEnumerable<T> QueryProc<T>(this DataConnection connection, T template, string sql, params DataParameter[] parameters)
Parameters
connectionDataConnectionDatabase connection.
templateTThis value used only for
Tparameter type inference, which makes this method usable with anonymous types.sqlstringCommand text.
parametersDataParameter[]Command parameters.
Returns
- IEnumerable<T>
Returns collection of query result records.
Type Parameters
TResult record type.
QueryProc<T>(DataConnection, T, string, object?)
Executes stored procedure and returns results as collection of values of specified type.
public static IEnumerable<T> QueryProc<T>(this DataConnection connection, T template, string sql, object? parameters)
Parameters
connectionDataConnectionDatabase connection.
templateTThis value used only for
Tparameter type inference, which makes this method usable with anonymous types.sqlstringCommand text.
parametersobjectCommand parameters. Supported values:
-
nullfor command without parameters;- single DataParameter instance;
- array of DataParameter parameters;
- mapping class entity.
Last case will convert all mapped columns to DataParameter instances using following logic:
- if column is of DataParameter type, column value will be used. If parameter name (Name) is not set, column name will be used;
- if converter from column type to DataParameter is defined in mapping schema, it will be used to create parameter with column name passed to converter;
- otherwise column value will be converted to DataParameter using column name as parameter name and column value will be converted to parameter value using conversion, defined by mapping schema.
Returns
- IEnumerable<T>
Returns collection of query result records.
Type Parameters
TResult record type.
QueryToArrayAsync<T>(DataConnection, Func<DbDataReader, T>, string)
Executes command asynchronously and returns array of values, mapped using provided mapping function.
public static Task<T[]> QueryToArrayAsync<T>(this DataConnection connection, Func<DbDataReader, T> objectReader, string sql)
Parameters
connectionDataConnectionDatabase connection.
objectReaderFunc<DbDataReader, T>Record mapping function from data reader.
sqlstringCommand text.
Returns
- Task<T[]>
Returns task with array of query result records.
Type Parameters
TResult record type.
QueryToArrayAsync<T>(DataConnection, Func<DbDataReader, T>, string, params DataParameter[])
Executes command asynchronously and returns array of values, mapped using provided mapping function.
public static Task<T[]> QueryToArrayAsync<T>(this DataConnection connection, Func<DbDataReader, T> objectReader, string sql, params DataParameter[] parameters)
Parameters
connectionDataConnectionDatabase connection.
objectReaderFunc<DbDataReader, T>Record mapping function from data reader.
sqlstringCommand text.
parametersDataParameter[]Command parameters.
Returns
- Task<T[]>
Returns task with array of query result records.
Type Parameters
TResult record type.
QueryToArrayAsync<T>(DataConnection, Func<DbDataReader, T>, string, object?)
Executes command asynchronously and returns array of values, mapped using provided mapping function.
public static Task<T[]> QueryToArrayAsync<T>(this DataConnection connection, Func<DbDataReader, T> objectReader, string sql, object? parameters)
Parameters
connectionDataConnectionDatabase connection.
objectReaderFunc<DbDataReader, T>Record mapping function from data reader.
sqlstringCommand text.
parametersobjectCommand parameters. Supported values:
-
nullfor command without parameters;- single DataParameter instance;
- array of DataParameter parameters;
- mapping class entity.
Last case will convert all mapped columns to DataParameter instances using following logic:
- if column is of DataParameter type, column value will be used. If parameter name (Name) is not set, column name will be used;
- if converter from column type to DataParameter is defined in mapping schema, it will be used to create parameter with column name passed to converter;
- otherwise column value will be converted to DataParameter using column name as parameter name and column value will be converted to parameter value using conversion, defined by mapping schema.
Returns
- Task<T[]>
Returns task with array of query result records.
Type Parameters
TResult record type.
QueryToArrayAsync<T>(DataConnection, Func<DbDataReader, T>, string, CancellationToken)
Executes command asynchronously and returns array of values, mapped using provided mapping function.
public static Task<T[]> QueryToArrayAsync<T>(this DataConnection connection, Func<DbDataReader, T> objectReader, string sql, CancellationToken cancellationToken)
Parameters
connectionDataConnectionDatabase connection.
objectReaderFunc<DbDataReader, T>Record mapping function from data reader.
sqlstringCommand text.
cancellationTokenCancellationTokenAsynchronous operation cancellation token.
Returns
- Task<T[]>
Returns task with array of query result records.
Type Parameters
TResult record type.
QueryToArrayAsync<T>(DataConnection, Func<DbDataReader, T>, string, CancellationToken, params DataParameter[])
Executes command asynchronously and returns array of values, mapped using provided mapping function.
public static Task<T[]> QueryToArrayAsync<T>(this DataConnection connection, Func<DbDataReader, T> objectReader, string sql, CancellationToken cancellationToken, params DataParameter[] parameters)
Parameters
connectionDataConnectionDatabase connection.
objectReaderFunc<DbDataReader, T>Record mapping function from data reader.
sqlstringCommand text.
cancellationTokenCancellationTokenAsynchronous operation cancellation token.
parametersDataParameter[]Command parameters.
Returns
- Task<T[]>
Returns task with array of query result records.
Type Parameters
TResult record type.
QueryToArrayAsync<T>(DataConnection, Func<DbDataReader, T>, string, CancellationToken, object?)
Executes command asynchronously and returns array of values, mapped using provided mapping function.
public static Task<T[]> QueryToArrayAsync<T>(this DataConnection connection, Func<DbDataReader, T> objectReader, string sql, CancellationToken cancellationToken, object? parameters)
Parameters
connectionDataConnectionDatabase connection.
objectReaderFunc<DbDataReader, T>Record mapping function from data reader.
sqlstringCommand text.
cancellationTokenCancellationTokenAsynchronous operation cancellation token.
parametersobjectCommand parameters. Supported values:
-
nullfor command without parameters;- single DataParameter instance;
- array of DataParameter parameters;
- mapping class entity.
Last case will convert all mapped columns to DataParameter instances using following logic:
- if column is of DataParameter type, column value will be used. If parameter name (Name) is not set, column name will be used;
- if converter from column type to DataParameter is defined in mapping schema, it will be used to create parameter with column name passed to converter;
- otherwise column value will be converted to DataParameter using column name as parameter name and column value will be converted to parameter value using conversion, defined by mapping schema.
Returns
- Task<T[]>
Returns task with array of query result records.
Type Parameters
TResult record type.
QueryToArrayAsync<T>(DataConnection, string)
Executes command asynchronously and returns array of values.
public static Task<T[]> QueryToArrayAsync<T>(this DataConnection connection, string sql)
Parameters
connectionDataConnectionDatabase connection.
sqlstringCommand text.
Returns
- Task<T[]>
Returns task with array of query result records.
Type Parameters
TResult record type.
QueryToArrayAsync<T>(DataConnection, string, DataParameter)
Executes command asynchronously and returns array of values.
public static Task<T[]> QueryToArrayAsync<T>(this DataConnection connection, string sql, DataParameter parameter)
Parameters
connectionDataConnectionDatabase connection.
sqlstringCommand text.
parameterDataParameterCommand parameter.
Returns
- Task<T[]>
Returns task with array of query result records.
Type Parameters
TResult record type.
QueryToArrayAsync<T>(DataConnection, string, DataParameter, CancellationToken)
Executes command asynchronously and returns array of values.
public static Task<T[]> QueryToArrayAsync<T>(this DataConnection connection, string sql, DataParameter parameter, CancellationToken cancellationToken)
Parameters
connectionDataConnectionDatabase connection.
sqlstringCommand text.
parameterDataParameterCommand parameter.
cancellationTokenCancellationTokenAsynchronous operation cancellation token.
Returns
- Task<T[]>
Returns task with array of query result records.
Type Parameters
TResult record type.
QueryToArrayAsync<T>(DataConnection, string, params DataParameter[])
Executes command asynchronously and returns array of values.
public static Task<T[]> QueryToArrayAsync<T>(this DataConnection connection, string sql, params DataParameter[] parameters)
Parameters
connectionDataConnectionDatabase connection.
sqlstringCommand text.
parametersDataParameter[]Command parameters.
Returns
- Task<T[]>
Returns task with array of query result records.
Type Parameters
TResult record type.
QueryToArrayAsync<T>(DataConnection, string, object?)
Executes command asynchronously and returns array of values.
public static Task<T[]> QueryToArrayAsync<T>(this DataConnection connection, string sql, object? parameters)
Parameters
connectionDataConnectionDatabase connection.
sqlstringCommand text.
parametersobjectCommand parameters. Supported values:
-
nullfor command without parameters;- single DataParameter instance;
- array of DataParameter parameters;
- mapping class entity.
Last case will convert all mapped columns to DataParameter instances using following logic:
- if column is of DataParameter type, column value will be used. If parameter name (Name) is not set, column name will be used;
- if converter from column type to DataParameter is defined in mapping schema, it will be used to create parameter with column name passed to converter;
- otherwise column value will be converted to DataParameter using column name as parameter name and column value will be converted to parameter value using conversion, defined by mapping schema.
Returns
- Task<T[]>
Returns task with array of query result records.
Type Parameters
TResult record type.
QueryToArrayAsync<T>(DataConnection, string, CancellationToken)
Executes command asynchronously and returns array of values.
public static Task<T[]> QueryToArrayAsync<T>(this DataConnection connection, string sql, CancellationToken cancellationToken)
Parameters
connectionDataConnectionDatabase connection.
sqlstringCommand text.
cancellationTokenCancellationTokenAsynchronous operation cancellation token.
Returns
- Task<T[]>
Returns task with array of query result records.
Type Parameters
TResult record type.
QueryToArrayAsync<T>(DataConnection, string, CancellationToken, params DataParameter[])
Executes command asynchronously and returns array of values.
public static Task<T[]> QueryToArrayAsync<T>(this DataConnection connection, string sql, CancellationToken cancellationToken, params DataParameter[] parameters)
Parameters
connectionDataConnectionDatabase connection.
sqlstringCommand text.
cancellationTokenCancellationTokenAsynchronous operation cancellation token.
parametersDataParameter[]Command parameters.
Returns
- Task<T[]>
Returns task with array of query result records.
Type Parameters
TResult record type.
QueryToArrayAsync<T>(DataConnection, string, CancellationToken, object?)
Executes command asynchronously and returns array of values.
public static Task<T[]> QueryToArrayAsync<T>(this DataConnection connection, string sql, CancellationToken cancellationToken, object? parameters)
Parameters
connectionDataConnectionDatabase connection.
sqlstringCommand text.
cancellationTokenCancellationTokenAsynchronous operation cancellation token.
parametersobjectCommand parameters. Supported values:
-
nullfor command without parameters;- single DataParameter instance;
- array of DataParameter parameters;
- mapping class entity.
Last case will convert all mapped columns to DataParameter instances using following logic:
- if column is of DataParameter type, column value will be used. If parameter name (Name) is not set, column name will be used;
- if converter from column type to DataParameter is defined in mapping schema, it will be used to create parameter with column name passed to converter;
- otherwise column value will be converted to DataParameter using column name as parameter name and column value will be converted to parameter value using conversion, defined by mapping schema.
Returns
- Task<T[]>
Returns task with array of query result records.
Type Parameters
TResult record type.
QueryToArrayAsync<T>(DataConnection, T, string, params DataParameter[])
Executes command asynchronously and returns array of values of specified type.
public static Task<T[]> QueryToArrayAsync<T>(this DataConnection connection, T template, string sql, params DataParameter[] parameters)
Parameters
connectionDataConnectionDatabase connection.
templateTThis value used only for
Tparameter type inference, which makes this method usable with anonymous types.sqlstringCommand text.
parametersDataParameter[]Command parameters.
Returns
- Task<T[]>
Returns task with array of query result records.
Type Parameters
TResult record type.
QueryToArrayAsync<T>(DataConnection, T, string, object?)
Executes command asynchronously and returns array of values of specified type.
public static Task<T[]> QueryToArrayAsync<T>(this DataConnection connection, T template, string sql, object? parameters)
Parameters
connectionDataConnectionDatabase connection.
templateTThis value used only for
Tparameter type inference, which makes this method usable with anonymous types.sqlstringCommand text.
parametersobjectCommand parameters. Supported values:
-
nullfor command without parameters;- single DataParameter instance;
- array of DataParameter parameters;
- mapping class entity.
Last case will convert all mapped columns to DataParameter instances using following logic:
- if column is of DataParameter type, column value will be used. If parameter name (Name) is not set, column name will be used;
- if converter from column type to DataParameter is defined in mapping schema, it will be used to create parameter with column name passed to converter;
- otherwise column value will be converted to DataParameter using column name as parameter name and column value will be converted to parameter value using conversion, defined by mapping schema.
Returns
- Task<T[]>
Returns task with array of query result records.
Type Parameters
TResult record type.
QueryToArrayAsync<T>(DataConnection, T, string, CancellationToken, params DataParameter[])
Executes command asynchronously and returns array of values of specified type.
public static Task<T[]> QueryToArrayAsync<T>(this DataConnection connection, T template, string sql, CancellationToken cancellationToken, params DataParameter[] parameters)
Parameters
connectionDataConnectionDatabase connection.
templateTThis value used only for
Tparameter type inference, which makes this method usable with anonymous types.sqlstringCommand text.
cancellationTokenCancellationTokenAsynchronous operation cancellation token.
parametersDataParameter[]Command parameters.
Returns
- Task<T[]>
Returns task with array of query result records.
Type Parameters
TResult record type.
QueryToArrayAsync<T>(DataConnection, T, string, CancellationToken, object?)
Executes command asynchronously and returns array of values of specified type.
public static Task<T[]> QueryToArrayAsync<T>(this DataConnection connection, T template, string sql, CancellationToken cancellationToken, object? parameters)
Parameters
connectionDataConnectionDatabase connection.
templateTThis value used only for
Tparameter type inference, which makes this method usable with anonymous types.sqlstringCommand text.
cancellationTokenCancellationTokenAsynchronous operation cancellation token.
parametersobjectCommand parameters. Supported values:
-
nullfor command without parameters;- single DataParameter instance;
- array of DataParameter parameters;
- mapping class entity.
Last case will convert all mapped columns to DataParameter instances using following logic:
- if column is of DataParameter type, column value will be used. If parameter name (Name) is not set, column name will be used;
- if converter from column type to DataParameter is defined in mapping schema, it will be used to create parameter with column name passed to converter;
- otherwise column value will be converted to DataParameter using column name as parameter name and column value will be converted to parameter value using conversion, defined by mapping schema.
Returns
- Task<T[]>
Returns task with array of query result records.
Type Parameters
TResult record type.
QueryToListAsync<T>(DataConnection, Func<DbDataReader, T>, string)
Executes command asynchronously and returns list of values, mapped using provided mapping function.
public static Task<List<T>> QueryToListAsync<T>(this DataConnection connection, Func<DbDataReader, T> objectReader, string sql)
Parameters
connectionDataConnectionDatabase connection.
objectReaderFunc<DbDataReader, T>Record mapping function from data reader.
sqlstringCommand text.
Returns
Type Parameters
TResult record type.
QueryToListAsync<T>(DataConnection, Func<DbDataReader, T>, string, params DataParameter[])
Executes command asynchronously and returns list of values, mapped using provided mapping function.
public static Task<List<T>> QueryToListAsync<T>(this DataConnection connection, Func<DbDataReader, T> objectReader, string sql, params DataParameter[] parameters)
Parameters
connectionDataConnectionDatabase connection.
objectReaderFunc<DbDataReader, T>Record mapping function from data reader.
sqlstringCommand text.
parametersDataParameter[]Command parameters.
Returns
Type Parameters
TResult record type.
QueryToListAsync<T>(DataConnection, Func<DbDataReader, T>, string, object?)
Executes command asynchronously and returns list of values, mapped using provided mapping function.
public static Task<List<T>> QueryToListAsync<T>(this DataConnection connection, Func<DbDataReader, T> objectReader, string sql, object? parameters)
Parameters
connectionDataConnectionDatabase connection.
objectReaderFunc<DbDataReader, T>Record mapping function from data reader.
sqlstringCommand text.
parametersobjectCommand parameters. Supported values:
-
nullfor command without parameters;- single DataParameter instance;
- array of DataParameter parameters;
- mapping class entity.
Last case will convert all mapped columns to DataParameter instances using following logic:
- if column is of DataParameter type, column value will be used. If parameter name (Name) is not set, column name will be used;
- if converter from column type to DataParameter is defined in mapping schema, it will be used to create parameter with column name passed to converter;
- otherwise column value will be converted to DataParameter using column name as parameter name and column value will be converted to parameter value using conversion, defined by mapping schema.
Returns
Type Parameters
TResult record type.
QueryToListAsync<T>(DataConnection, Func<DbDataReader, T>, string, object?, CancellationToken)
Executes command asynchronously and returns list of values, mapped using provided mapping function.
public static Task<List<T>> QueryToListAsync<T>(this DataConnection connection, Func<DbDataReader, T> objectReader, string sql, object? parameters, CancellationToken cancellationToken)
Parameters
connectionDataConnectionDatabase connection.
objectReaderFunc<DbDataReader, T>Record mapping function from data reader.
sqlstringCommand text.
parametersobjectCommand parameters. Supported values:
-
nullfor command without parameters;- single DataParameter instance;
- array of DataParameter parameters;
- mapping class entity.
Last case will convert all mapped columns to DataParameter instances using following logic:
- if column is of DataParameter type, column value will be used. If parameter name (Name) is not set, column name will be used;
- if converter from column type to DataParameter is defined in mapping schema, it will be used to create parameter with column name passed to converter;
- otherwise column value will be converted to DataParameter using column name as parameter name and column value will be converted to parameter value using conversion, defined by mapping schema.
cancellationTokenCancellationTokenAsynchronous operation cancellation token.
Returns
Type Parameters
TResult record type.
QueryToListAsync<T>(DataConnection, Func<DbDataReader, T>, string, CancellationToken)
Executes command asynchronously and returns list of values, mapped using provided mapping function.
public static Task<List<T>> QueryToListAsync<T>(this DataConnection connection, Func<DbDataReader, T> objectReader, string sql, CancellationToken cancellationToken)
Parameters
connectionDataConnectionDatabase connection.
objectReaderFunc<DbDataReader, T>Record mapping function from data reader.
sqlstringCommand text.
cancellationTokenCancellationTokenAsynchronous operation cancellation token.
Returns
Type Parameters
TResult record type.
QueryToListAsync<T>(DataConnection, Func<DbDataReader, T>, string, CancellationToken, params DataParameter[])
Executes command asynchronously and returns list of values, mapped using provided mapping function.
public static Task<List<T>> QueryToListAsync<T>(this DataConnection connection, Func<DbDataReader, T> objectReader, string sql, CancellationToken cancellationToken, params DataParameter[] parameters)
Parameters
connectionDataConnectionDatabase connection.
objectReaderFunc<DbDataReader, T>Record mapping function from data reader.
sqlstringCommand text.
cancellationTokenCancellationTokenAsynchronous operation cancellation token.
parametersDataParameter[]Command parameters.
Returns
Type Parameters
TResult record type.
QueryToListAsync<T>(DataConnection, string)
Executes command asynchronously and returns list of values.
public static Task<List<T>> QueryToListAsync<T>(this DataConnection connection, string sql)
Parameters
connectionDataConnectionDatabase connection.
sqlstringCommand text.
Returns
Type Parameters
TResult record type.
QueryToListAsync<T>(DataConnection, string, DataParameter)
Executes command asynchronously and returns list of values.
public static Task<List<T>> QueryToListAsync<T>(this DataConnection connection, string sql, DataParameter parameter)
Parameters
connectionDataConnectionDatabase connection.
sqlstringCommand text.
parameterDataParameterCommand parameter.
Returns
Type Parameters
TResult record type.
QueryToListAsync<T>(DataConnection, string, DataParameter, CancellationToken)
Executes command asynchronously and returns list of values.
public static Task<List<T>> QueryToListAsync<T>(this DataConnection connection, string sql, DataParameter parameter, CancellationToken cancellationToken)
Parameters
connectionDataConnectionDatabase connection.
sqlstringCommand text.
parameterDataParameterCommand parameter.
cancellationTokenCancellationTokenAsynchronous operation cancellation token.
Returns
Type Parameters
TResult record type.
QueryToListAsync<T>(DataConnection, string, params DataParameter[])
Executes command asynchronously and returns list of values.
public static Task<List<T>> QueryToListAsync<T>(this DataConnection connection, string sql, params DataParameter[] parameters)
Parameters
connectionDataConnectionDatabase connection.
sqlstringCommand text.
parametersDataParameter[]Command parameters.
Returns
Type Parameters
TResult record type.
QueryToListAsync<T>(DataConnection, string, object?)
Executes command asynchronously and returns list of values.
public static Task<List<T>> QueryToListAsync<T>(this DataConnection connection, string sql, object? parameters)
Parameters
connectionDataConnectionDatabase connection.
sqlstringCommand text.
parametersobjectCommand parameters. Supported values:
-
nullfor command without parameters;- single DataParameter instance;
- array of DataParameter parameters;
- mapping class entity.
Last case will convert all mapped columns to DataParameter instances using following logic:
- if column is of DataParameter type, column value will be used. If parameter name (Name) is not set, column name will be used;
- if converter from column type to DataParameter is defined in mapping schema, it will be used to create parameter with column name passed to converter;
- otherwise column value will be converted to DataParameter using column name as parameter name and column value will be converted to parameter value using conversion, defined by mapping schema.
Returns
Type Parameters
TResult record type.
QueryToListAsync<T>(DataConnection, string, CancellationToken)
Executes command asynchronously and returns list of values.
public static Task<List<T>> QueryToListAsync<T>(this DataConnection connection, string sql, CancellationToken cancellationToken)
Parameters
connectionDataConnectionDatabase connection.
sqlstringCommand text.
cancellationTokenCancellationTokenAsynchronous operation cancellation token.
Returns
Type Parameters
TResult record type.
QueryToListAsync<T>(DataConnection, string, CancellationToken, params DataParameter[])
Executes command asynchronously and returns list of values.
public static Task<List<T>> QueryToListAsync<T>(this DataConnection connection, string sql, CancellationToken cancellationToken, params DataParameter[] parameters)
Parameters
connectionDataConnectionDatabase connection.
sqlstringCommand text.
cancellationTokenCancellationTokenAsynchronous operation cancellation token.
parametersDataParameter[]Command parameters.
Returns
Type Parameters
TResult record type.
QueryToListAsync<T>(DataConnection, string, CancellationToken, object?)
Executes command asynchronously and returns list of values.
public static Task<List<T>> QueryToListAsync<T>(this DataConnection connection, string sql, CancellationToken cancellationToken, object? parameters)
Parameters
connectionDataConnectionDatabase connection.
sqlstringCommand text.
cancellationTokenCancellationTokenAsynchronous operation cancellation token.
parametersobjectCommand parameters. Supported values:
-
nullfor command without parameters;- single DataParameter instance;
- array of DataParameter parameters;
- mapping class entity.
Last case will convert all mapped columns to DataParameter instances using following logic:
- if column is of DataParameter type, column value will be used. If parameter name (Name) is not set, column name will be used;
- if converter from column type to DataParameter is defined in mapping schema, it will be used to create parameter with column name passed to converter;
- otherwise column value will be converted to DataParameter using column name as parameter name and column value will be converted to parameter value using conversion, defined by mapping schema.
Returns
Type Parameters
TResult record type.
QueryToListAsync<T>(DataConnection, T, string, params DataParameter[])
Executes command asynchronously and returns list of values of specified type.
public static Task<List<T>> QueryToListAsync<T>(this DataConnection connection, T template, string sql, params DataParameter[] parameters)
Parameters
connectionDataConnectionDatabase connection.
templateTThis value used only for
Tparameter type inference, which makes this method usable with anonymous types.sqlstringCommand text.
parametersDataParameter[]Command parameters.
Returns
Type Parameters
TResult record type.
QueryToListAsync<T>(DataConnection, T, string, object?)
Executes command asynchronously and returns list of values of specified type.
public static Task<List<T>> QueryToListAsync<T>(this DataConnection connection, T template, string sql, object? parameters)
Parameters
connectionDataConnectionDatabase connection.
templateTThis value used only for
Tparameter type inference, which makes this method usable with anonymous types.sqlstringCommand text.
parametersobjectCommand parameters. Supported values:
-
nullfor command without parameters;- single DataParameter instance;
- array of DataParameter parameters;
- mapping class entity.
Last case will convert all mapped columns to DataParameter instances using following logic:
- if column is of DataParameter type, column value will be used. If parameter name (Name) is not set, column name will be used;
- if converter from column type to DataParameter is defined in mapping schema, it will be used to create parameter with column name passed to converter;
- otherwise column value will be converted to DataParameter using column name as parameter name and column value will be converted to parameter value using conversion, defined by mapping schema.
Returns
Type Parameters
TResult record type.
QueryToListAsync<T>(DataConnection, T, string, CancellationToken, params DataParameter[])
Executes command asynchronously and returns list of values of specified type.
public static Task<List<T>> QueryToListAsync<T>(this DataConnection connection, T template, string sql, CancellationToken cancellationToken, params DataParameter[] parameters)
Parameters
connectionDataConnectionDatabase connection.
templateTThis value used only for
Tparameter type inference, which makes this method usable with anonymous types.sqlstringCommand text.
cancellationTokenCancellationTokenAsynchronous operation cancellation token.
parametersDataParameter[]Command parameters.
Returns
Type Parameters
TResult record type.
QueryToListAsync<T>(DataConnection, T, string, CancellationToken, object?)
Executes command asynchronously and returns list of values of specified type.
public static Task<List<T>> QueryToListAsync<T>(this DataConnection connection, T template, string sql, CancellationToken cancellationToken, object? parameters)
Parameters
connectionDataConnectionDatabase connection.
templateTThis value used only for
Tparameter type inference, which makes this method usable with anonymous types.sqlstringCommand text.
cancellationTokenCancellationTokenAsynchronous operation cancellation token.
parametersobjectCommand parameters. Supported values:
-
nullfor command without parameters;- single DataParameter instance;
- array of DataParameter parameters;
- mapping class entity.
Last case will convert all mapped columns to DataParameter instances using following logic:
- if column is of DataParameter type, column value will be used. If parameter name (Name) is not set, column name will be used;
- if converter from column type to DataParameter is defined in mapping schema, it will be used to create parameter with column name passed to converter;
- otherwise column value will be converted to DataParameter using column name as parameter name and column value will be converted to parameter value using conversion, defined by mapping schema.
Returns
Type Parameters
TResult record type.
Query<T>(DataConnection, Func<DbDataReader, T>, string)
Executes command and returns results as collection of values, mapped using provided mapping function.
public static IEnumerable<T> Query<T>(this DataConnection connection, Func<DbDataReader, T> objectReader, string sql)
Parameters
connectionDataConnectionDatabase connection.
objectReaderFunc<DbDataReader, T>Record mapping function from data reader.
sqlstringCommand text.
Returns
- IEnumerable<T>
Returns collection of query result records.
Type Parameters
TResult record type.
Query<T>(DataConnection, Func<DbDataReader, T>, string, params DataParameter[])
Executes command and returns results as collection of values, mapped using provided mapping function.
public static IEnumerable<T> Query<T>(this DataConnection connection, Func<DbDataReader, T> objectReader, string sql, params DataParameter[] parameters)
Parameters
connectionDataConnectionDatabase connection.
objectReaderFunc<DbDataReader, T>Record mapping function from data reader.
sqlstringCommand text.
parametersDataParameter[]Command parameters.
Returns
- IEnumerable<T>
Returns collection of query result records.
Type Parameters
TResult record type.
Query<T>(DataConnection, Func<DbDataReader, T>, string, object?)
Executes command and returns results as collection of values, mapped using provided mapping function.
public static IEnumerable<T> Query<T>(this DataConnection connection, Func<DbDataReader, T> objectReader, string sql, object? parameters)
Parameters
connectionDataConnectionDatabase connection.
objectReaderFunc<DbDataReader, T>Record mapping function from data reader.
sqlstringCommand text.
parametersobjectCommand parameters. Supported values:
-
nullfor command without parameters;- single DataParameter instance;
- array of DataParameter parameters;
- mapping class entity.
Last case will convert all mapped columns to DataParameter instances using following logic:
- if column is of DataParameter type, column value will be used. If parameter name (Name) is not set, column name will be used;
- if converter from column type to DataParameter is defined in mapping schema, it will be used to create parameter with column name passed to converter;
- otherwise column value will be converted to DataParameter using column name as parameter name and column value will be converted to parameter value using conversion, defined by mapping schema.
Returns
- IEnumerable<T>
Returns collection of query result records.
Type Parameters
TResult record type.
Query<T>(DataConnection, string)
Executes command and returns results as collection of values of specified type.
public static IEnumerable<T> Query<T>(this DataConnection connection, string sql)
Parameters
connectionDataConnectionDatabase connection.
sqlstringCommand text.
Returns
- IEnumerable<T>
Returns collection of query result records.
Type Parameters
TResult record type.
Query<T>(DataConnection, string, DataParameter)
Executes command and returns results as collection of values of specified type.
public static IEnumerable<T> Query<T>(this DataConnection connection, string sql, DataParameter parameter)
Parameters
connectionDataConnectionDatabase connection.
sqlstringCommand text.
parameterDataParameterCommand parameter.
Returns
- IEnumerable<T>
Returns collection of query result records.
Type Parameters
TResult record type.
Query<T>(DataConnection, string, params DataParameter[])
Executes command and returns results as collection of values of specified type.
public static IEnumerable<T> Query<T>(this DataConnection connection, string sql, params DataParameter[] parameters)
Parameters
connectionDataConnectionDatabase connection.
sqlstringCommand text.
parametersDataParameter[]Command parameters.
Returns
- IEnumerable<T>
Returns collection of query result records.
Type Parameters
TResult record type.
Query<T>(DataConnection, string, object?)
Executes command and returns results as collection of values of specified type.
public static IEnumerable<T> Query<T>(this DataConnection connection, string sql, object? parameters)
Parameters
connectionDataConnectionDatabase connection.
sqlstringCommand text.
parametersobjectCommand parameters. Supported values:
-
nullfor command without parameters;- single DataParameter instance;
- array of DataParameter parameters;
- mapping class entity.
Last case will convert all mapped columns to DataParameter instances using following logic:
- if column is of DataParameter type, column value will be used. If parameter name (Name) is not set, column name will be used;
- if converter from column type to DataParameter is defined in mapping schema, it will be used to create parameter with column name passed to converter;
- otherwise column value will be converted to DataParameter using column name as parameter name and column value will be converted to parameter value using conversion, defined by mapping schema.
Returns
- IEnumerable<T>
Returns collection of query result records.
Type Parameters
TResult record type.
Query<T>(DataConnection, T, string, params DataParameter[])
Executes command and returns results as collection of values of specified type.
public static IEnumerable<T> Query<T>(this DataConnection connection, T template, string sql, params DataParameter[] parameters)
Parameters
connectionDataConnectionDatabase connection.
templateTThis value used only for
Tparameter type inference, which makes this method usable with anonymous types.sqlstringCommand text.
parametersDataParameter[]Command parameters.
Returns
- IEnumerable<T>
Returns collection of query result records.
Type Parameters
TResult record type.
Query<T>(DataConnection, T, string, object?)
Executes command and returns results as collection of values of specified type.
public static IEnumerable<T> Query<T>(this DataConnection connection, T template, string sql, object? parameters)
Parameters
connectionDataConnectionDatabase connection.
templateTThis value used only for
Tparameter type inference, which makes this method usable with anonymous types.sqlstringCommand text.
parametersobjectCommand parameters. Supported values:
-
nullfor command without parameters;- single DataParameter instance;
- array of DataParameter parameters;
- mapping class entity.
Last case will convert all mapped columns to DataParameter instances using following logic:
- if column is of DataParameter type, column value will be used. If parameter name (Name) is not set, column name will be used;
- if converter from column type to DataParameter is defined in mapping schema, it will be used to create parameter with column name passed to converter;
- otherwise column value will be converted to DataParameter using column name as parameter name and column value will be converted to parameter value using conversion, defined by mapping schema.
Returns
- IEnumerable<T>
Returns collection of query result records.
Type Parameters
TResult record type.
SetCommand(DataConnection, string)
Creates command wrapper for current connection with provided command text.
public static CommandInfo SetCommand(this DataConnection dataConnection, string commandText)
Parameters
dataConnectionDataConnectionDatabase connection.
commandTextstringCommand text.
Returns
- CommandInfo
Database command wrapper.
SetCommand(DataConnection, string, DataParameter)
Creates command wrapper for current connection with provided command text and single parameter.
public static CommandInfo SetCommand(this DataConnection dataConnection, string commandText, DataParameter parameter)
Parameters
dataConnectionDataConnectionDatabase connection.
commandTextstringCommand text.
parameterDataParameterCommand parameter.
Returns
- CommandInfo
Database command wrapper.
SetCommand(DataConnection, string, params DataParameter[])
Creates command wrapper for current connection with provided command text and parameters.
public static CommandInfo SetCommand(this DataConnection dataConnection, string commandText, params DataParameter[] parameters)
Parameters
dataConnectionDataConnectionDatabase connection.
commandTextstringCommand text.
parametersDataParameter[]Command parameters.
Returns
- CommandInfo
Database command wrapper.
SetCommand(DataConnection, string, object?)
Creates command wrapper for current connection with provided command text and parameters.
public static CommandInfo SetCommand(this DataConnection dataConnection, string commandText, object? parameters)
Parameters
dataConnectionDataConnectionDatabase connection.
commandTextstringCommand text.
parametersobjectCommand parameters. Supported values:
-
nullfor command without parameters;- single DataParameter instance;
- array of DataParameter parameters;
- mapping class entity.
Last case will convert all mapped columns to DataParameter instances using following logic:
- if column is of DataParameter type, column value will be used. If parameter name (Name) is not set, column name will be used;
- if converter from column type to DataParameter is defined in mapping schema, it will be used to create parameter with column name passed to converter;
- otherwise column value will be converted to DataParameter using column name as parameter name and column value will be converted to parameter value using conversion, defined by mapping schema.
Returns
- CommandInfo
Database command wrapper.