Bug #84423 .net core - TableAttribute doesn't work, but .ToTable() works
Submitted: 5 Jan 2017 17:24 Modified: 16 May 2017 22:34
Reporter: Avi Kenjale Email Updates:
Status: Closed Impact on me:
None 
Category:Connector / NET Severity:S3 (Non-critical)
Version:6.10.0 OS:Microsoft Windows (any)
Assigned to: Gabriela Martinez Sanchez CPU Architecture:Any

[5 Jan 2017 17:24] Avi Kenjale
Description:
Note: I am using MySQL & its sample database 'World'

Project.json

"frameworks": {
    "netstandard1.6": {
      "dependencies": {
        "NETStandard.Library": "1.6.1",
        "MySQL.Data.EntityFrameworkCore":"7.0.6-ir31"
      }
     }
  }
Model:

using System.ComponentModel.DataAnnotations.Schema;
[Table("Country")]   // This is actual table name in database
    public class Countries
    {
        [Key]
        public string Code { get; set; }
        public string Name { get; set; }
        public string Continent { get; set; }
        public string Region { get; set; }
        public int IndepYear { get; set; }
    }
DbContext:

public class WorldContext : DbContext
 { 
         DbSet<Countries> Countries {get;set;}

        protected override void OnConfiguring(DbContextOptionsBuilder optionBuilder)
        {            optionBuilder.UseMySQL("server=localhost;userid=root;pwd=Newuser123;port=3306;database=world;sslmode=none;");
        }
}

When I write code to fill & fetch Countries using linq, I am getting error like 'Countries' table does not exist.

However, when I comment the [Table("Country")] from model class, and add following code under context class, it works:

protected override void OnModelCreating(ModelBuilder modelBuilder)
 {
       modelBuilder.Entity<Countries>()
           .ToTable("Country");
 }

NOTE: created issue for same on github - https://github.com/aspnet/EntityFramework/issues/7319

How to repeat:
Detailed steps provided in description

Suggested fix:
I tried changing MySQL native package to "Pomelo.EntityFrameworkCore.MySql": "1.1.1-prerelease-10009", and TableAttribute works.
[9 Jan 2017 20:34] Gabriela Martinez Sanchez
Could you please give it a try with this version
https://www.nuget.org/packages/MySql.Data.EntityFrameworkCore/6.10.0-alpha
?
The 7.0.6-ir31 does not support the latest EF Core version.
[9 Jan 2017 21:25] Avi Kenjale
I tried. No luck. Still having same issue.
[9 Jan 2017 21:26] Avi Kenjale
Exception message: Table 'world.countries' doesn't exist
[16 May 2017 22:34] Christine Cole
Posted by developer:
 
Fixed as of the upcoming MySQL Connector/NET 6.10.2 release, and here's the changelog entry:

EF Core: Using System.ComponentModel.DataAnnotations.Schema.TableAttribute
to initialize a new class instance that specified the name of an existing
MySQL table produced incorrect table name and column name mappings.

Thank you for the bug report.