Bug #94343 EF6 Code first - table schemas are lost, but automatic migrations uses them
Submitted: 15 Feb 2019 11:33 Modified: 24 Jul 2020 17:20
Reporter: Spartak Timchev Email Updates:
Status: Closed Impact on me:
Category:Connector / NET Severity:S2 (Serious)
Version:6.9.12, 8.0.15 OS:Any
Assigned to: CPU Architecture:Any
Tags: EF6, entityframework

[15 Feb 2019 11:33] Spartak Timchev
In Code first, When both table name and schema are used in entity's attribute, for example [Table("table1", Schema = "myschema")], automatic migrations do respect the table schema name, creating table with name "myschema.table1", but when, after initial creation of database by automatic migrations, I am trying to get/insert/delete records in this table using EF6, an exception is thrown, and from what can be seen from the log, the error description is:

"-- Failed in 2 ms with error: Table 'mydb.table1' doesn't exist"

Obviously, the EF6 part of the connector/net does not respect table schemas at all. It should look for "mydb.myschema.table1" instead.

This was OK in 6.9.9 version.

How to repeat:
1. Create code first project for EF6.

2. Enable automatic migrations

3. Create the folowing Entity:
[Table("table1", Schema = "myschema")]
public class MyEntity
public int ID {get;set;}
public int Name {get;set;}

4. Create DBContext derived class with DbSet for table as follows:
public class MyDbContext : DbContext
public DbSet<MyEntity> TestTable {get;set;}

5. Try to use the above context for accessing the database and put records in TestTable dbset.

Suggested fix:
EF6 part of the MySql Connector/.Net must respect table schemas both in automatic migrations and normal use.
[24 Jul 2020 17:20] Christine Cole
Posted by developer:
Fixed as of the upcoming MySQL Connector/NET 8.0.22 release, and here's the proposed changelog entry from the documentation team:

Entity Framework code-first migration omitted the schema attribute that
was assigned to an entity, although the automatic migration appeared to
generate a table with the proper schema value at first. Subsequent queries
using the schema name returned errors.

Thank you for the bug report.