I am using EFCore to connect to a MySQL 5.7 server, and trying to connect my DbContext to multiple schemas at the same time, however it is always defaulting to the database that I have specified in my connection string
"ConnectionStrings": {
"Database": "server=localhost; port=3306; user id=user; password=pass; database=schema1;"
}
In my Context class I am trying to set up the entities to have different schemas using the ToTable("table", "schema") property
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.Entity<User>(entity =>
{
entity.ToTable("users", "schema1");
});
modelBuilder.Entity<Order>(entity =>
{
entity.ToTable("orders", "schema2");
});
}
Unfortunately when I try to retrieve data from the database I get the following error:
MySql.Data.MySqlClient.MySqlException: 'Table 'schema1.orders' doesn't exist'
If I try something clearly wrong, like
entity.ToTable("schema2.orders", "schema2");
Then I unsurprisingly get the error:
MySql.Data.MySqlClient.MySqlException: 'Table 'schema1.schema2.orders' doesn't exist'
So it appears as though it is always just using the database from the connection string.
If I modify the connection string to remove the database, which I believe is a step in the right direction.
"ConnectionStrings": {
"Database": "server=localhost; port=3306; user id=user; password=pass;"
}
Then I get the following error:
MySql.Data.MySqlClient.MySqlException: 'No database selected'
Is what I am trying to achieve possible with a MySQL connection, or is support for this feature limited to specific DB engines