Interface IMigrationContext
The surface available to an IMigration while it runs. Everything here executes on the migration's own connection and transaction (DDL excepted — MySQL auto-commits it). Provides raw SQL helpers plus a bridge into the declarative schema sync so a migration can bring a table to its current model shape and then transform data in the same step.
public interface IMigrationContext
Properties
Connection
The migration's open connection.
MySqlConnection Connection { get; }
Property Value
- MySqlConnection
Transaction
The migration's open transaction.
MySqlTransaction Transaction { get; }
Property Value
- MySqlTransaction
Methods
ExecuteAsync(string, IReadOnlyDictionary<string, object?>?, CancellationToken)
Runs a non-query statement (INSERT/UPDATE/DELETE/DDL) and returns affected rows.
Task<int> ExecuteAsync(string sql, IReadOnlyDictionary<string, object?>? parameters = null, CancellationToken ct = default)
Parameters
sqlstringparametersIReadOnlyDictionary<string, object>ctCancellationToken
Returns
QueryAsync<T>(string, IReadOnlyDictionary<string, object?>?, CancellationToken)
Runs a query and materializes each row into T.
Task<List<T>> QueryAsync<T>(string sql, IReadOnlyDictionary<string, object?>? parameters = null, CancellationToken ct = default) where T : class, new()
Parameters
sqlstringparametersIReadOnlyDictionary<string, object>ctCancellationToken
Returns
Type Parameters
T
ScalarAsync<T>(string, IReadOnlyDictionary<string, object?>?, CancellationToken)
Runs a query returning a single scalar (first column of the first row).
Task<T?> ScalarAsync<T>(string sql, IReadOnlyDictionary<string, object?>? parameters = null, CancellationToken ct = default)
Parameters
sqlstringparametersIReadOnlyDictionary<string, object>ctCancellationToken
Returns
- Task<T>
Type Parameters
T
SyncTableAsync<T>(CancellationToken)
Brings the table for T to its current model shape via the schema
analyzer (CREATE if missing, otherwise additive ALTERs). Lets a migration add only the data
transform around it. Note: this issues DDL, which MySQL commits immediately.
Task SyncTableAsync<T>(CancellationToken ct = default) where T : class
Parameters
Returns
Type Parameters
T