Class RelationalCommand
- Namespace
- Microsoft.EntityFrameworkCore.Storage
- Assembly
- Microsoft.EntityFrameworkCore.Relational.dll
A command to be executed against a relational database.
This type is typically used by database providers (and other extensions). It is generally not used in application code.
public class RelationalCommand : IRelationalCommand
- Inheritance
-
RelationalCommand
- Implements
- Inherited Members
Constructors
RelationalCommand(RelationalCommandBuilderDependencies, string, IReadOnlyList<IRelationalParameter>)
Constructs a new RelationalCommand.
This type is typically used by database providers (and other extensions). It is generally not used in application code.
public RelationalCommand(RelationalCommandBuilderDependencies dependencies, string commandText, IReadOnlyList<IRelationalParameter> parameters)
Parameters
dependencies
RelationalCommandBuilderDependenciesService dependencies.
commandText
stringThe text of the command to be executed.
parameters
IReadOnlyList<IRelationalParameter>Parameters for the command.
Properties
CommandText
Gets the command text to be executed.
public virtual string CommandText { get; }
Property Value
Dependencies
Command building dependencies.
protected virtual RelationalCommandBuilderDependencies Dependencies { get; }
Property Value
Parameters
Gets the parameters for the command.
public virtual IReadOnlyList<IRelationalParameter> Parameters { get; }
Property Value
Methods
CreateDbCommand(RelationalCommandParameterObject, Guid, DbCommandMethod)
Called by the execute methods to create a DbCommand for the given DbConnection and configure timeouts and transactions.
This method is typically used by database providers (and other extensions). It is generally not used in application code.
public virtual DbCommand CreateDbCommand(RelationalCommandParameterObject parameterObject, Guid commandId, DbCommandMethod commandMethod)
Parameters
parameterObject
RelationalCommandParameterObjectParameters for this method.
commandId
GuidThe command correlation ID.
commandMethod
DbCommandMethodThe method that will be called on the created command.
Returns
- DbCommand
The created command.
CreateRelationalDataReader(IRelationalConnection, DbCommand, DbDataReader, Guid, IDiagnosticsLogger<Command>)
Creates a new RelationalDataReader to be used by ExecuteReader(RelationalCommandParameterObject) and ExecuteReaderAsync(RelationalCommandParameterObject, CancellationToken).
This method is typically used by database providers (and other extensions). It is generally not used in application code.
protected virtual RelationalDataReader CreateRelationalDataReader(IRelationalConnection connection, DbCommand command, DbDataReader reader, Guid commandId, IDiagnosticsLogger<DbLoggerCategory.Database.Command> logger)
Parameters
connection
IRelationalConnectionThe connection, to pass to the RelationalDataReader constructor.
command
DbCommandThe command that was executed, to pass to the RelationalDataReader constructor.
reader
DbDataReaderThe underlying reader for the result set, to pass to the RelationalDataReader constructor.
commandId
GuidA correlation ID that identifies the DbCommand instance being used, to pass to the RelationalDataReader constructor.
logger
IDiagnosticsLogger<Command>The diagnostic source, to pass to the RelationalDataReader constructor.
Returns
- RelationalDataReader
The created RelationalDataReader.
ExecuteNonQuery(RelationalCommandParameterObject)
Executes the command with no results.
public virtual int ExecuteNonQuery(RelationalCommandParameterObject parameterObject)
Parameters
parameterObject
RelationalCommandParameterObjectParameters for this method.
Returns
- int
The number of rows affected.
ExecuteNonQueryAsync(RelationalCommandParameterObject, CancellationToken)
Asynchronously executes the command with no results.
public virtual Task<int> ExecuteNonQueryAsync(RelationalCommandParameterObject parameterObject, CancellationToken cancellationToken = default)
Parameters
parameterObject
RelationalCommandParameterObjectParameters for this method.
cancellationToken
CancellationTokenA CancellationToken to observe while waiting for the task to complete.
Returns
- Task<int>
A task that represents the asynchronous operation. The task result contains the number of rows affected.
ExecuteReader(RelationalCommandParameterObject)
Executes the command with a RelationalDataReader result.
public virtual RelationalDataReader ExecuteReader(RelationalCommandParameterObject parameterObject)
Parameters
parameterObject
RelationalCommandParameterObjectParameters for this method.
Returns
- RelationalDataReader
The result of the command.
ExecuteReaderAsync(RelationalCommandParameterObject, CancellationToken)
Asynchronously executes the command with a RelationalDataReader result.
public virtual Task<RelationalDataReader> ExecuteReaderAsync(RelationalCommandParameterObject parameterObject, CancellationToken cancellationToken = default)
Parameters
parameterObject
RelationalCommandParameterObjectParameters for this method.
cancellationToken
CancellationTokenA CancellationToken to observe while waiting for the task to complete.
Returns
- Task<RelationalDataReader>
A task that represents the asynchronous operation. The task result contains the result of the command.
ExecuteScalar(RelationalCommandParameterObject)
Executes the command with a single scalar result.
public virtual object ExecuteScalar(RelationalCommandParameterObject parameterObject)
Parameters
parameterObject
RelationalCommandParameterObjectParameters for this method.
Returns
- object
The result of the command.
ExecuteScalarAsync(RelationalCommandParameterObject, CancellationToken)
Asynchronously executes the command with a single scalar result.
public virtual Task<object> ExecuteScalarAsync(RelationalCommandParameterObject parameterObject, CancellationToken cancellationToken = default)
Parameters
parameterObject
RelationalCommandParameterObjectParameters for this method.
cancellationToken
CancellationTokenA CancellationToken to observe while waiting for the task to complete.