You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Software versions
MySqlConnector version: 2.3.7
Server type (MySQL, MariaDB, Aurora, etc.) and version: MySQL 8.0.35
.NET version: 8.0.8
ORM NuGet packages and versions:
Pomelo.EntityFrameworkCore.MySql 8.0.2
Microsoft.EntityFrameworkCore.Relational 8.0.8
Describe the bug
I have an extension method that adds DbContext and MySqlDataSource and configures EF Core to work with the MySqlDataSource.
Extension method
For the specified connection string, the connection string parameters - AutoEnlist and UseXaTransactions are forcibly set to true and false, respectively.
usingSystem;usingMicrosoft.EntityFrameworkCore;usingMicrosoft.Extensions.DependencyInjection;usingMicrosoft.Extensions.Hosting;usingMySqlConnector;namespaceMySql.Extensions;publicstaticclassServiceCollectionExtensions{publicstaticIServiceCollectionAddCustomDbContext<TContext>(thisIServiceCollectionservices,stringconnectionString,stringapplicationName,ServiceLifetimecontextLifetime=ServiceLifetime.Scoped,ServiceLifetimeoptionsLifetime=ServiceLifetime.Scoped)whereTContext:DbContext{ArgumentNullException.ThrowIfNull(services);varconnectionStringBuilder=newMySqlConnectionStringBuilder(connectionString){AutoEnlist=true,UseXaTransactions=false,AllowUserVariables=true,ApplicationName=applicationName};varruntimeConnectionString=connectionStringBuilder.ConnectionString;vardataSourceKeyProvider=newMySqlDataSourceKeyProvider<TContext>(applicationName);services.AddSingleton(dataSourceKeyProvider);services.AddKeyedMySqlDataSource(dataSourceKeyProvider.DataSourceKey,runtimeConnectionString);services.AddDbContext<TContext>(static(provider,builder)=>{vardataSourceKeyProvider=provider.GetRequiredService<MySqlDataSourceKeyProvider<TContext>>();vardataSourceKey=dataSourceKeyProvider.DataSourceKey;varhostEnvironment=provider.GetRequiredService<IHostEnvironment>();varmysqlDataSource=provider.GetRequiredKeyedService<MySqlDataSource>(dataSourceKey);builder.UseMySql(mysqlDataSource,Constants.MySqlServerVersion,static mysql =>{mysql.MigrationsAssembly(typeof(TContext).Assembly.GetName().FullName);mysql.UseMicrosoftJson();});if(hostEnvironment.IsDevelopment()){builder.EnableSensitiveDataLogging();builder.EnableDetailedErrors();}},contextLifetime,optionsLifetime);returnservices;}privatesealedclassMySqlDataSourceKeyProvider<TContext>whereTContext:DbContext{publicMySqlDataSourceKeyProvider(stringdataSourceKey){if(string.IsNullOrWhiteSpace(dataSourceKey)){thrownewArgumentException("Value cannot be null or whitespace.",nameof(dataSourceKey));}DataSourceKey=dataSourceKey;}publicstringDataSourceKey{get;}}}
I also have a global action filter that sets up a transaction for any ASP.NET Core MVC action using System.Transactions.
In the logs, I see all events and commands except for the transaction commit.
However, the commit itself is executed.
After debugging the code, I noticed that when OnCommit is called in the StandardEnlistedTransaction at the Connection object, all properties in the LoggingConfiguration contain NullLogger.
Software versions
MySqlConnector version: 2.3.7
Server type (MySQL, MariaDB, Aurora, etc.) and version: MySQL 8.0.35
.NET version: 8.0.8
ORM NuGet packages and versions:
Pomelo.EntityFrameworkCore.MySql 8.0.2
Microsoft.EntityFrameworkCore.Relational 8.0.8
Describe the bug
I have an extension method that adds DbContext and MySqlDataSource and configures EF Core to work with the MySqlDataSource.
Extension method
For the specified connection string, the connection string parameters - AutoEnlist and UseXaTransactions are forcibly set to true and false, respectively.
I also have a global action filter that sets up a transaction for any ASP.NET Core MVC action using
System.Transactions
.Action filter
In the logs, I see all events and commands except for the transaction commit.
However, the commit itself is executed.
After debugging the code, I noticed that when
OnCommit
is called in theStandardEnlistedTransaction
at theConnection
object, all properties in theLoggingConfiguration
containNullLogger
.It appears as though the issue lies in this code segment related to closing the connection when using EnlistedTransaction.
A new MySqlConnection instance is created, but logging parameters are not passed to it.
After this, the new
MySqlConnection
instance begins using the global logging configuration, which by default containsNullLogger
.The text was updated successfully, but these errors were encountered: