Class CommandInfo
Provides database connection command abstraction.
public class CommandInfo
- Inheritance
-
CommandInfo
- Extension Methods
Constructors
CommandInfo(DataConnection, string)
Creates database command instance using provided database connection and command text.
public CommandInfo(DataConnection dataConnection, string commandText)
Parameters
dataConnection
DataConnectionDatabase connection instance.
commandText
stringCommand text.
CommandInfo(DataConnection, string, DataParameter)
Creates database command instance using provided database connection, command text and single parameter.
public CommandInfo(DataConnection dataConnection, string commandText, DataParameter parameter)
Parameters
dataConnection
DataConnectionDatabase connection instance.
commandText
stringCommand text.
parameter
DataParameterCommand parameter.
CommandInfo(DataConnection, string, params DataParameter[])
Creates database command instance using provided database connection, command text and parameters.
public CommandInfo(DataConnection dataConnection, string commandText, params DataParameter[] parameters)
Parameters
dataConnection
DataConnectionDatabase connection instance.
commandText
stringCommand text.
parameters
DataParameter[]List of command parameters.
CommandInfo(DataConnection, string, object?)
Creates database command instance using provided database connection, command text and parameters.
public CommandInfo(DataConnection dataConnection, string commandText, object? parameters)
Parameters
dataConnection
DataConnectionDatabase connection instance.
commandText
stringCommand text.
parameters
objectCommand parameters. Supported values:
-
null
for 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 colum 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.
Fields
CommandBehavior
Command behavior flags. See CommandBehavior for more details. Default value: Default.
public CommandBehavior CommandBehavior
Field Value
CommandText
Command text.
public string CommandText
Field Value
CommandType
Type of command. See CommandType for all supported types. Default value: Text.
public CommandType CommandType
Field Value
DataConnection
Instance of database connection, associated with command.
public DataConnection DataConnection
Field Value
Parameters
Command parameters.
public DataParameter[]? Parameters
Field Value
Methods
ClearObjectReaderCache()
Clears global cache of object mapping functions from query results and mapping functions from value to DataParameter.
public static void ClearObjectReaderCache()
Execute()
Executes command and returns number of affected records.
public int Execute()
Returns
- int
Number of records, affected by command execution.
ExecuteAsync(CancellationToken)
Executes command asynchronously and returns number of affected records.
public Task<int> ExecuteAsync(CancellationToken cancellationToken = default)
Parameters
cancellationToken
CancellationTokenAsynchronous operation cancellation token.
Returns
ExecuteAsync<T>(CancellationToken)
Executes command asynchronously and returns single value.
public Task<T> ExecuteAsync<T>(CancellationToken cancellationToken = default)
Parameters
cancellationToken
CancellationTokenAsynchronous operation cancellation token.
Returns
- Task<T>
Task with resulting value.
Type Parameters
T
Resulting value type.
ExecuteProc()
Executes command using StoredProcedure command type and returns number of affected records. Saves result values for output and reference parameters to corresponding DataParameter object.
public int ExecuteProc()
Returns
- int
Number of records, affected by command execution.
ExecuteProcAsync(CancellationToken)
Executes command using StoredProcedure command type asynchronously and returns number of affected records. Saves result values for output and reference parameters to corresponding DataParameter object.
public Task<int> ExecuteProcAsync(CancellationToken cancellationToken = default)
Parameters
cancellationToken
CancellationTokenAsynchronous operation cancellation token.
Returns
ExecuteProcAsync<T>(CancellationToken)
Executes command using StoredProcedure command type asynchronously and returns single value. Saves result values for output and reference parameters to corresponding DataParameter object.
public Task<T> ExecuteProcAsync<T>(CancellationToken cancellationToken = default)
Parameters
cancellationToken
CancellationTokenAsynchronous operation cancellation token.
Returns
- Task<T>
Task with resulting value.
Type Parameters
T
Resulting value type.
ExecuteProc<T>()
Executes command using StoredProcedure command type and returns single value.
public T ExecuteProc<T>()
Returns
- T
Resulting value.
Type Parameters
T
Resulting value type.
ExecuteReader()
Executes command and returns data reader instance.
public DataReader ExecuteReader()
Returns
- DataReader
Data reader object.
ExecuteReaderAsync(CancellationToken)
Executes command asynchronously and returns data reader instance.
public Task<DataReaderAsync> ExecuteReaderAsync(CancellationToken cancellationToken = default)
Parameters
cancellationToken
CancellationTokenAsynchronous operation cancellation token.
Returns
- Task<DataReaderAsync>
Task with data reader object.
ExecuteReaderProc()
Executes command using StoredProcedure command type and returns data reader instance.
public DataReader ExecuteReaderProc()
Returns
- DataReader
Data reader object.
ExecuteReaderProcAsync(CancellationToken)
Executes command asynchronously using StoredProcedure command type and returns data reader instance.
public Task<DataReaderAsync> ExecuteReaderProcAsync(CancellationToken cancellationToken = default)
Parameters
cancellationToken
CancellationTokenAsynchronous operation cancellation token.
Returns
- Task<DataReaderAsync>
Data reader object.
Execute<T>()
Executes command and returns single value. Saves result values for output and reference parameters to corresponding DataParameter object.
public T Execute<T>()
Returns
- T
Resulting value.
Type Parameters
T
Resulting value type.
QueryAsync<T>(Func<DbDataReader, T>, CancellationToken)
Executes command asynchronously and returns results as collection of values, mapped using provided mapping function.
public Task<IEnumerable<T>> QueryAsync<T>(Func<DbDataReader, T> objectReader, CancellationToken cancellationToken = default)
Parameters
objectReader
Func<DbDataReader, T>Record mapping function from data reader.
cancellationToken
CancellationTokenAsynchronous operation cancellation token.
Returns
- Task<IEnumerable<T>>
Returns collection of query result records.
Type Parameters
T
Result record type.
QueryAsync<T>(CancellationToken)
Executes command asynchronously and returns results as collection of values of specified type.
public Task<IEnumerable<T>> QueryAsync<T>(CancellationToken cancellationToken = default)
Parameters
cancellationToken
CancellationTokenAsynchronous operation cancellation token.
Returns
- Task<IEnumerable<T>>
Returns collection of query result records.
Type Parameters
T
Result record type.
QueryForEachAsync<T>(Action<T>, CancellationToken)
Executes command asynchronously and apply provided action to each record.
public Task QueryForEachAsync<T>(Action<T> action, CancellationToken cancellationToken = default)
Parameters
action
Action<T>Action, applied to each result record.
cancellationToken
CancellationTokenAsynchronous operation cancellation token.
Returns
- Task
Returns task.
Type Parameters
T
Result record type.
QueryForEachAsync<T>(Func<DbDataReader, T>, Action<T>, CancellationToken)
Executes command asynchronously and apply provided action to each record, mapped using provided mapping function.
public Task QueryForEachAsync<T>(Func<DbDataReader, T> objectReader, Action<T> action, CancellationToken cancellationToken = default)
Parameters
objectReader
Func<DbDataReader, T>Record mapping function from data reader.
action
Action<T>Action, applied to each result record.
cancellationToken
CancellationTokenAsynchronous operation cancellation token.
Returns
- Task
Returns task.
Type Parameters
T
Result record type.
QueryMultipleAsync<T>(CancellationToken)
Executes command asynchronously and returns a result containing multiple result sets. Saves result values for output and reference parameters to corresponding DataParameter object.
public Task<T> QueryMultipleAsync<T>(CancellationToken cancellationToken = default) where T : class
Parameters
cancellationToken
CancellationTokenAsynchronous operation cancellation token.
Returns
- Task<T>
A task that represents the asynchronous operation. The task result contains object with multiply result sets.
Type Parameters
T
Result set type.
QueryMultiple<T>()
Executes command and returns a result containing multiple result sets.
public T QueryMultiple<T>() where T : class
Returns
- T
Returns result.
Type Parameters
T
Result set type.
QueryProcAsync<T>(Func<DbDataReader, T>, CancellationToken)
Executes command asynchronously using StoredProcedure command type and returns results as collection of values, mapped using provided mapping function.
public Task<IEnumerable<T>> QueryProcAsync<T>(Func<DbDataReader, T> objectReader, CancellationToken cancellationToken = default)
Parameters
objectReader
Func<DbDataReader, T>Record mapping function from data reader.
cancellationToken
CancellationTokenAsynchronous operation cancellation token.
Returns
- Task<IEnumerable<T>>
Returns collection of query result records.
Type Parameters
T
Result record type.
QueryProcAsync<T>(CancellationToken)
Executes command asynchronously using StoredProcedure command type and returns results as collection of values of specified type.
public Task<IEnumerable<T>> QueryProcAsync<T>(CancellationToken cancellationToken = default)
Parameters
cancellationToken
CancellationTokenAsynchronous operation cancellation token.
Returns
- Task<IEnumerable<T>>
Returns collection of query result records.
Type Parameters
T
Result record type.
QueryProcAsync<T>(T, CancellationToken)
Executes command asynchronously using StoredProcedure command type and returns results as collection of values of specified type.
public Task<IEnumerable<T>> QueryProcAsync<T>(T template, CancellationToken cancellationToken = default)
Parameters
template
TThis value used only for
T
parameter type inference, which makes this method usable with anonymous types.cancellationToken
CancellationTokenAsynchronous operation cancellation token.
Returns
- Task<IEnumerable<T>>
Returns collection of query result records.
Type Parameters
T
Result record type.
QueryProcMultipleAsync<T>(CancellationToken)
Executes command asynchronously using StoredProcedure command type and returns a result containing multiple result sets.
public Task<T> QueryProcMultipleAsync<T>(CancellationToken cancellationToken = default) where T : class
Parameters
cancellationToken
CancellationTokenAsynchronous operation cancellation token.
Returns
- Task<T>
A task that represents the asynchronous operation. The task result contains object with multiply result sets.
Type Parameters
T
Result set type.
QueryProcMultiple<T>()
Executes command using StoredProcedure command type and returns a result containing multiple result sets. Saves result values for output and reference parameters to corresponding DataParameter object.
public T QueryProcMultiple<T>() where T : class
Returns
- T
Returns result.
Type Parameters
T
Result set type.
QueryProc<T>()
Executes command using StoredProcedure command type and returns results as collection of values of specified type.
public IEnumerable<T> QueryProc<T>()
Returns
- IEnumerable<T>
Returns collection of query result records.
Type Parameters
T
Result record type.
QueryProc<T>(Func<DbDataReader, T>)
Executes command using StoredProcedure command type and returns results as collection of values, mapped using provided mapping function.
public IEnumerable<T> QueryProc<T>(Func<DbDataReader, T> objectReader)
Parameters
objectReader
Func<DbDataReader, T>Record mapping function from data reader.
Returns
- IEnumerable<T>
Returns collection of query result records.
Type Parameters
T
Result record type.
QueryProc<T>(T)
Executes command using StoredProcedure command type and returns results as collection of values of specified type.
public IEnumerable<T> QueryProc<T>(T template)
Parameters
template
TThis value used only for
T
parameter type inference, which makes this method usable with anonymous types.
Returns
- IEnumerable<T>
Returns collection of query result records.
Type Parameters
T
Result record type.
QueryToArrayAsync<T>(Func<DbDataReader, T>, CancellationToken)
Executes command asynchronously and returns array of values, mapped using provided mapping function.
public Task<T[]> QueryToArrayAsync<T>(Func<DbDataReader, T> objectReader, CancellationToken cancellationToken = default)
Parameters
objectReader
Func<DbDataReader, T>Record mapping function from data reader.
cancellationToken
CancellationTokenAsynchronous operation cancellation token.
Returns
- Task<T[]>
Returns task with array of query result records.
Type Parameters
T
Result record type.
QueryToArrayAsync<T>(CancellationToken)
Executes command asynchronously and returns array of values.
public Task<T[]> QueryToArrayAsync<T>(CancellationToken cancellationToken = default)
Parameters
cancellationToken
CancellationTokenAsynchronous operation cancellation token.
Returns
- Task<T[]>
Returns task with array of query result records.
Type Parameters
T
Result record type.
QueryToListAsync<T>(Func<DbDataReader, T>, CancellationToken)
Executes command asynchronously and returns list of values, mapped using provided mapping function.
public Task<List<T>> QueryToListAsync<T>(Func<DbDataReader, T> objectReader, CancellationToken cancellationToken = default)
Parameters
objectReader
Func<DbDataReader, T>Record mapping function from data reader.
cancellationToken
CancellationTokenAsynchronous operation cancellation token.
Returns
Type Parameters
T
Result record type.
QueryToListAsync<T>(CancellationToken)
Executes command asynchronously and returns list of values.
public Task<List<T>> QueryToListAsync<T>(CancellationToken cancellationToken = default)
Parameters
cancellationToken
CancellationTokenAsynchronous operation cancellation token.
Returns
Type Parameters
T
Result record type.
Query<T>()
Executes command and returns results as collection of values of specified type.
public IEnumerable<T> Query<T>()
Returns
- IEnumerable<T>
Returns collection of query result records.
Type Parameters
T
Result record type.
Query<T>(Func<DbDataReader, T>)
Executes command and returns results as collection of values, mapped using provided mapping function.
public IEnumerable<T> Query<T>(Func<DbDataReader, T> objectReader)
Parameters
objectReader
Func<DbDataReader, T>Record mapping function from data reader.
Returns
- IEnumerable<T>
Returns collection of query result records.
Type Parameters
T
Result record type.
Query<T>(T)
Executes command and returns results as collection of values of specified type.
public IEnumerable<T> Query<T>(T template)
Parameters
template
TThis value used only for
T
parameter type inference, which makes this method usable with anonymous types.
Returns
- IEnumerable<T>
Returns collection of query result records.
Type Parameters
T
Result record type.