Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mqsql ef core Migration assembly

   services.AddDbContextPool<CPSContext>(
                    options => options.UseMySql(connectionString,

                        mySqlOptions =>
                        {
                            mySqlOptions.ServerVersion(new Version(5, 7, 17), ServerType.MariaDb)
                            .EnableRetryOnFailure(
                            maxRetryCount: 10,
                            maxRetryDelay: TimeSpan.FromSeconds(30),
                            errorNumbersToAdd: null);
                        }
                    ));

Acoove is my connection string..

I am getting below error

enter image description here

How to add migraton assemmbly to connection i am sin pamlio.ef core

b => b.MigrationsAssembly(typeof(CPSContext).Assembly.FullName))

Initial My confi was

//services.AddDbContext<CPSContext>(options =>
            //options.UseMySQL(connectionString, b => b.MigrationsAssembly(typeof(CPSContext).Assembly.FullName)));

Connection string: "CPS": "server=195.22.106.22:3307;database=corepigm_standard;user=corepigm_admin;password=Db@dmin2;"

How to use port number in conncetion string.i a getting below erro

enter image description here

like image 294
Ajt Avatar asked Mar 11 '26 01:03

Ajt


1 Answers

Migrations assembly and similar is set on the options builder argument of the UseMySql call (named mySqlOptions in the code in question) similar to your initial configuration.

However the ServerVersion is not part of the options (hence the compile time error you are getting), but separate parameter of UseMySql between connection string and options builder, as can be seen in the commented code of the screenshot. Also it cannot be created using class constructors, but some static factory methods like AutoDetect, Parse, Create etc.

So the code matching your attempt is something like this

services.AddDbContextPool<CPSContext>(
    options => options.UseMySql(connectionString,
        ServerVersion.Create(new Version(5, 7, 17), ServerType.MariaDb),
        mySqlOptions =>
        {
            mySqlOptions.EnableRetryOnFailure(
                maxRetryCount: 10,
                maxRetryDelay: TimeSpan.FromSeconds(30),
                errorNumbersToAdd: null);

            mySqlOptions.MigrationsAssembly(typeof(CPSContext).Assembly.FullName);
        }
    ));

Reference: Configuration Options topic of Pomelo provider.

like image 73
Ivan Stoev Avatar answered Mar 13 '26 20:03

Ivan Stoev



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!