-
-
Notifications
You must be signed in to change notification settings - Fork 393
Configuration Options
We use MySqlConnector underneath for all communication between Pomelo.EntityFrameworkCore and MySQL. For a complete list of all connection string options, see MySQL .NET Connection String Options.
Since 2.1.0. Informs the provider of the capabilities of the MySQL server. If you are using an older version such as MySQL 5.5, you will want to specify this option.
Default: latest version of MySQL Server
services.AddDbContext<AppDb>(
options => options.UseMySql(connection,
mysqlOptions =>
{
mysqlOptions
.ServerVersion(new Version(5, 7, 17), ServerType.MySql);
}
));
Since 2.1.0. These 3 options control how Character Sets are appended to String columns.
Default: if string columns are marked as ANSI strings, they will be created with CHARACTER SET latin1
by default.
Example:
services.AddDbContext<AppDb>(
options => options.UseMySql(connection,
mysqlOptions =>
{
mysqlOptions
.CharSetBehavior(CharSetBehavior.AppendToAllColumns)
.AnsiCharSet(CharSet.Latin1)
.UnicodeCharSet(CharSet.Utf8mb4);
}
));
The escaping style can be configured to support SQL mode NO_BACKSLASH_ESCAPES by adding .DisableBackslashEscaping()
to your MySQL option configuration.
mysqlOptions =>
{
mysqlOptions
.ServerVersion(new Version(5, 7, 17), ServerType.MySql)
.DisableBackslashEscaping();
}
PLEASE NOTE This option is not necessary for common usage scenarios, because the provider handles all the necessary escaping for you automatically.
It does not set the SQL mode and will not check if it matches the actual database configuration either.
Do not use this option unless you are absolutely sure it will always be set when queries are performed on the context and you really need it.
You can add NO_BACKSLASH_ESCAPES
manually to the current SQL mode like this:
context.Database.ExecuteSqlCommand(
@"set session sql_mode = concat(@@sql_mode, ',', 'NO_BACKSLASH_ESCAPES')");
As of today, this option does not apply to parameter values in INSERT
or UPDATE
statements; do not use it when the context is used to update entries.
This behavior is likely to change in 3.0.