Class MySqlDataContext
Data context for MySQL. Wraps the MySqlConnector driver for connections and parameters and
renders SQL through MySqlDialect.
public class MySqlDataContext : DataContext, IDataContext, IQueryExecutor, IQueryMaterializer, IQueryPlanner, IRowReaderFactory, IQueryCache, IContextEnvironment, IRawCommandExecutor, IAsyncDisposable, IDisposable, IConnectionManager, ITransactionManager
- Inheritance
-
MySqlDataContext
- Implements
- Derived
- Inherited Members
- Extension Methods
Remarks
The bulk-insert executor is re-implemented here (the base hook cannot carry the whole-invocation
budget or the explicit option presence) so BulkInsertMode is resolved by the provider,
the native MySqlBulkCopy prerequisites are checked read-only before a row is read, and
MariaDB (its derived context) can add its scoped session controls.
Constructors
MySqlDataContext(DbConnection, DataContextBuilder)
Creates a MySQL context over a caller-supplied connection, which the context does not dispose.
public MySqlDataContext(DbConnection connection, DataContextBuilder optionsBuilder)
Parameters
connectionDbConnectionAn already-created
DbConnectionowned by the caller.optionsBuilderDataContextBuilderThe options collected from
DataContextBuilder.
MySqlDataContext(string, DataContextBuilder)
Creates a MySQL context that owns a connection built lazily from
connectionString.
public MySqlDataContext(string connectionString, DataContextBuilder optionsBuilder)
Parameters
connectionStringstringThe connection string used to create the
MySqlConnection.optionsBuilderDataContextBuilderThe options collected from
DataContextBuilder.
MySqlDataContext(string?, DbConnection?, DataContextBuilder, Version?)
Creates a context with an optional connection string or a caller-supplied connection and
snapshots the provider server serverVersion once. Derived providers (MariaDB)
forward their version here so the base ServerVersion snapshot agrees
with the dialect they build.
protected MySqlDataContext(string? connectionString, DbConnection? providedConnection, DataContextBuilder optionsBuilder, Version? serverVersion)
Parameters
connectionStringstringConnection string used to create a context-owned connection, or null.
providedConnectionDbConnectionAn already-created connection owned by the caller, or null.
optionsBuilderDataContextBuilderThe options collected from
DataContextBuilder.serverVersionVersionThe provider server version to snapshot, or null for unset.
Properties
Dialect
SQL dialect used to render queries. Supplied by the provider; SQL generation depends on this interface rather than on the context itself.
public override ISqlDialect Dialect { get; }
Property Value
TimeOnlyProjectionRefusal
MySQL has no time of day: TIME is a signed duration that may be negative or exceed 24 h, so a
TimeOnly projection would have to truncate or reject values the column legitimately
holds. The projection is refused and the duration stays available through TimeSpan.
protected override string? TimeOnlyProjectionRefusal { get; }
Property Value
Methods
CreateDbConnection(string?)
Creates a new MySqlConnection for connectionString.
protected override DbConnection CreateDbConnection(string? connectionString)
Parameters
connectionStringstringThe MySQL connection string.
Returns
- DbConnection
A new, unopened MySQL connection.
CreateParam(DbCommand, string, object?)
Mints the parameter through the executing command so it belongs to the connection's actual
driver: MySql.Data (the driver of Oracle's EF Core provider) rejects a
MySqlConnector.MySqlParameter in its parameter collection, and vice versa. No throwaway
command is created: the active command owns the parameter and the execution layer adds it.
protected override DbParameter CreateParam(DbCommand command, string name, object? value)
Parameters
commandDbCommandThe executing command the parameter will be added to.
namestringThe parameter name, without the provider prefix.
valueobjectThe parameter value, or null.
Returns
- DbParameter
A new MySQL parameter of the active connection's driver.
CreateParam(string, object?)
Creates a MySqlConnector parameter, mapping a null value to
DBNull.Value because MySqlConnector rejects an unset parameter value. This is the
public 2-arg factory; the execution paths use the command-aware overloads below so a command
from the active connection's driver mints the parameter.
public override DbParameter CreateParam(string name, object? value)
Parameters
namestringThe parameter name, without the provider prefix.
valueobjectThe parameter value, or null.
Returns
- DbParameter
A new MySQL parameter.
CreateProcedureParameter(ProcedureParameter)
Creates a MySqlParameter for a descriptor. A TableParameterValue is emulated
as a JSON text parameter (JSON_TABLE(@p, '$[*]' COLUMNS(...)) on MySQL 8.0+/MariaDB
10.6+). A TypeName is SQL Server only and is rejected.
protected override DbParameter CreateProcedureParameter(ProcedureParameter parameter)
Parameters
parameterProcedureParameterThe parameter descriptor.
Returns
- DbParameter
A new MySQL parameter configured from
parameter.
Remarks
Kept for compatibility with callers that hold no executing command; the raw/procedure execution
paths use the command-aware overload below, which mints the parameter through the command so it
belongs to the connection's actual driver. This command-unaware overload falls back to the 2-arg
CreateParam(string, object?) and is therefore not safe when the connection is
driven by MySql.Data.
Exceptions
- ArgumentException
Name is blank, TypeName is set (SQL Server only), or a table parameter is not Input.
CreateProcedureParameter(DbCommand, ProcedureParameter)
Command-aware variant used by the raw/procedure execution paths: mints the parameter through
command so it belongs to the connection's actual driver (MySql.Data vs
MySqlConnector), which is required when Oracle's EF Core provider owns the connection.
protected override DbParameter CreateProcedureParameter(DbCommand command, ProcedureParameter parameter)
Parameters
commandDbCommandThe executing command the parameter will be added to.
parameterProcedureParameterThe parameter descriptor.
Returns
- DbParameter
A new MySQL parameter of the active connection's driver.
Exceptions
- ArgumentException
Name is blank, TypeName is set (SQL Server only), or a table parameter is not Input.