Bug #94343 EF6 Code first - table schemas are lost, but automatic migrations uses them
Submitted: 15 Feb 11:33
Reporter: Spartak Timchev Email Updates:
Status: Open 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 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.