Enable primitive collections and refactor MySQL EF options.

Added support for primitive collections and parameterized collection translation in MySQL EF configurations. Removed redundant `EnablePrimitiveCollectionsSupport` calls in program configuration to centralize the behavior.
This commit is contained in:
Sipke Schoorstra 2024-12-28 20:06:33 +01:00
parent 021795f53a
commit 4ed58c67e6
2 changed files with 9 additions and 7 deletions

View file

@ -150,8 +150,8 @@ services
else if (sqlDatabaseProvider == SqlDatabaseProvider.PostgreSql)
ef.UsePostgreSql(postgresConnectionString!);
#if !NET9_0
else if (sqlDatabaseProvider == SqlDatabaseProvider.MySql)
ef.UseMySql(mySqlConnectionString, null, opt => opt.EnablePrimitiveCollectionsSupport());
else if (sqlDatabaseProvider == SqlDatabaseProvider.MySql)
ef.UseMySql(mySqlConnectionString);
#endif
else if (sqlDatabaseProvider == SqlDatabaseProvider.CockroachDb)
ef.UsePostgreSql(cockroachDbConnectionString!);
@ -187,7 +187,7 @@ services
ef.UsePostgreSql(postgresConnectionString!);
#if !NET9_0
else if (sqlDatabaseProvider == SqlDatabaseProvider.MySql)
ef.UseMySql(mySqlConnectionString, null, opt => opt.EnablePrimitiveCollectionsSupport());
ef.UseMySql(mySqlConnectionString);
#endif
else if (sqlDatabaseProvider == SqlDatabaseProvider.CockroachDb)
ef.UsePostgreSql(cockroachDbConnectionString!);
@ -233,7 +233,7 @@ services
ef.UsePostgreSql(postgresConnectionString!);
#if !NET9_0
else if (sqlDatabaseProvider == SqlDatabaseProvider.MySql)
ef.UseMySql(mySqlConnectionString, null, opt => opt.EnablePrimitiveCollectionsSupport());
ef.UseMySql(mySqlConnectionString);
#endif
else if (sqlDatabaseProvider == SqlDatabaseProvider.CockroachDb)
ef.UsePostgreSql(cockroachDbConnectionString!);
@ -361,7 +361,7 @@ services
ef.UsePostgreSql(postgresConnectionString);
#if !NET9_0
else if (sqlDatabaseProvider == SqlDatabaseProvider.MySql)
ef.UseMySql(mySqlConnectionString, null, opt => opt.EnablePrimitiveCollectionsSupport());
ef.UseMySql(mySqlConnectionString);
#endif
else if (sqlDatabaseProvider == SqlDatabaseProvider.CockroachDb)
ef.UsePostgreSql(cockroachDbConnectionString!);
@ -550,7 +550,7 @@ services
if (sqlDatabaseProvider == SqlDatabaseProvider.PostgreSql) ef.UsePostgreSql(postgresConnectionString);
#if !NET9_0
if (sqlDatabaseProvider == SqlDatabaseProvider.MySql)
ef.UseMySql(mySqlConnectionString, null, opt => opt.EnablePrimitiveCollectionsSupport());
ef.UseMySql(mySqlConnectionString);
#endif
if (sqlDatabaseProvider == SqlDatabaseProvider.CockroachDb) ef.UsePostgreSql(cockroachDbConnectionString);
});

View file

@ -23,7 +23,9 @@ public static class DbContextOptionsBuilderExtensions
db
.MigrationsAssembly(options.GetMigrationsAssemblyName(migrationsAssembly))
.MigrationsHistoryTable(options.GetMigrationsHistoryTableName(), options.GetSchemaName())
.SchemaBehavior(MySqlSchemaBehavior.Ignore);
.SchemaBehavior(MySqlSchemaBehavior.Ignore)
.EnablePrimitiveCollectionsSupport()
.TranslateParameterizedCollectionsToConstants();
configure?.Invoke(db);
});