Pomelo EntiryFramwork 7.0 from 3.1 code breaking changes

189 Views Asked by At

This code is in tge DatabaseDbProvider.cs ContextFactory and in the DbSetExtensions class

protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
    if (!optionsBuilder.IsConfigured)
    {
        optionsBuilder.UseMySql("Server=localhost;Port=3306;Database=beyond_migrator;User=maria_service;", mysqlOptions =>
        {
            mysqlOptions.ServerVersion(new Version(10, 3, 9), ServerType.MariaDb)
                        .CharSet(CharSet.Utf8Mb4)
                        .CharSetBehavior(CharSetBehavior.AppendToAllColumns);**
        });

    base.OnConfiguring(optionsBuilder);
}

MySqlDbContextOptionsBuilder does not contain the definition for ServerVersion

i see ways to solve the version 'MySQLDbContextOptionsBuilder' does not contain a definition for 'ServerVersion'

but Charset and CharSetBehavior give the error.. CharSet() is obsolete. Call the Fluent API extension method HasCharSet() on the builder object of you model/entities/properties instead. To get the exact behavio as with CharSet() call modelBuilder.HasCharSet(charSet, DelgationModes.ApplyToColums.

How exactly can i access the builder object for the entire model. This code above is only on connection. Did the developer not need to specifiy these in the connection in the first place?

The only place where ModelBuilder is accessable is in OnModelCreating in the DbContext file, or in migration files.

P.S. this all became an issue, when being tasked to upgrade a 3.1 entity framework project to a EF 7. Here is the reference to the other open question upgraded .net Entity Framework using MySql and Pomelo Entity Framework Core (3.1 5.0 6.0 7.0 ) using code first

2

There are 2 best solutions below

0
MichaelEvanchik On

is it safe to just do this?

optionsBuilder.UseMySql(ServerVersion.AutoDetect("Server=localhost;Port=3306;Database=beyond_migrator;User=maria_service;"));

and not worry about setting the CharSet and CharSetBehavior on connection?

0
Michael Evanchik On

above, DID NOT WORK

this was solution....

        optionsBuilder.UseMySql(sqlStringBuilder,
                                    new MySqlServerVersion(new Version(5, 3)),
                                    o => o.EnableRetryOnFailure()
                                    .MaxBatchSize(1000)
                                    .MinBatchSize(2)
                                );

still unsure what to do with CharSet, and CharSetBehavior