I’m having trouble with Entity Framework Core 8 and MySQL. The issue is that EF Core keeps adding the main database name from my connection string before every table name, even when those tables are in different databases.
Here’s my situation: I have one MySQL server running several databases (database1, database2, database3, etc). My connection string points to database1 as the main one. But I need to query tables that exist in database2 and database3.
When I run my LINQ queries, the generated SQL looks wrong:
SELECT ... FROM database1.database2.CustomerTable INNER JOIN database1.database3.OrderTable
Or sometimes:
SELECT ... FROM database1.CustomerTable INNER JOIN database1.OrderTable
I’m using EF Core 8 with Pomelo MySQL provider. I already tried using SchemaBehavior(MySqlSchemaBehavior.Ignore) and MySqlSchemaBehavior.Translate but it still adds the connection string database name. If I remove the default database from my connection string completely, I get errors.
Here’s my configuration:
services.AddDbContext<AppDbContext>(opts =>
opts.UseMySql(connectionString, new MySqlServerVersion(new Version(8, 0, 0)),
config => config.SchemaBehavior(MySqlSchemaBehavior.Ignore)
)
.LogTo(Console.WriteLine, LogLevel.Information)
);
How can I fix this?