Class MigrationCommand
- Namespace
- Microsoft.EntityFrameworkCore.Migrations
- Assembly
- Microsoft.EntityFrameworkCore.Relational.dll
Represents a command ready to be sent to the database to migrate it.
public class MigrationCommand
- Inheritance
-
MigrationCommand
- Inherited Members
Remarks
See Database migrations for more information and examples.
Constructors
MigrationCommand(IRelationalCommand, DbContext?, IRelationalCommandDiagnosticsLogger, bool)
Creates a new instance of the command.
public MigrationCommand(IRelationalCommand relationalCommand, DbContext? context, IRelationalCommandDiagnosticsLogger logger, bool transactionSuppressed = false)
Parameters
relationalCommandIRelationalCommandThe underlying IRelationalCommand that will be used to execute the command.
contextDbContextThe current Microsoft.EntityFrameworkCore.DbContext or null if not known.
loggerIRelationalCommandDiagnosticsLoggerThe command logger.
transactionSuppressedboolIndicates whether or not transactions should be suppressed while executing the command.
Properties
CommandLogger
The associated command logger.
public virtual IRelationalCommandDiagnosticsLogger CommandLogger { get; }
Property Value
CommandText
The SQL command text that will be executed against the database.
public virtual string CommandText { get; }
Property Value
TransactionSuppressed
Indicates whether or not transactions should be suppressed while executing the command.
public virtual bool TransactionSuppressed { get; }
Property Value
Methods
ExecuteNonQuery(IRelationalConnection, IReadOnlyDictionary<string, object?>?)
Executes the command and returns the number of rows affected.
public virtual int ExecuteNonQuery(IRelationalConnection connection, IReadOnlyDictionary<string, object?>? parameterValues = null)
Parameters
connectionIRelationalConnectionThe connection to execute against.
parameterValuesIReadOnlyDictionary<string, object>The values for the parameters, or null if the command has no parameters.
Returns
- int
The number of rows affected.
ExecuteNonQueryAsync(IRelationalConnection, IReadOnlyDictionary<string, object?>?, CancellationToken)
Executes the command and returns the number of rows affected.
public virtual Task<int> ExecuteNonQueryAsync(IRelationalConnection connection, IReadOnlyDictionary<string, object?>? parameterValues = null, CancellationToken cancellationToken = default)
Parameters
connectionIRelationalConnectionThe connection to execute against.
parameterValuesIReadOnlyDictionary<string, object>The values for the parameters, or null if the command has no parameters.
cancellationTokenCancellationTokenA 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.
Exceptions
- OperationCanceledException
If the CancellationToken is canceled.