Bug #61920 Table name ignored with Entity Framework Code First
Submitted: 20 Jul 2011 2:14 Modified: 4 Aug 2011 15:43
Reporter: Alexandr Ponomarenko Email Updates:
Status: Closed Impact on me:
None 
Category:Connector / NET Severity:S3 (Non-critical)
Version:6.4.3 OS:Any
Assigned to: Fernando Gonzalez.Sanchez CPU Architecture:Any
Tags: Table name ignored

[20 Jul 2011 2:14] Alexandr Ponomarenko
Description:
CreateDatabaseScript ignore changing name of table.

How to repeat:
public class my_aspnet_applications
{
    [Key]
    [MaxLength(11)]
    [Column("id")]
    public int Id { get; set; }

    [MaxLength(256)]
    [Column("name")]
    public string Name { get; set; }

    [MaxLength(256)]
    [Column("description")]
    public string Description { get; set; }
}

public class mySqlDbContext : DbContext
{
    public DbSet<my_aspnet_applications> my_aspnet_applicationsss { get; set; }

    protected override void OnModelCreating(DbModelBuilder modelBuilder)
    {
        modelBuilder.Configurations.Add<my_aspnet_applications>(new EntityTypeConfiguration<my_aspnet_applications>());
        modelBuilder.Entity<my_aspnet_applications>().ToTable("myPrefix_" + typeof(my_aspnet_applications).Name);
    }
}

Suggested fix:
MySql.Data.MySqlClient.MySqlProviderServices.GetTableCreateScript
{
    EntityType e = entitySet.ElementType;
    string tableName = "";
    MetadataProperty property;
    entitySet.MetadataProperties.TryGetValue("Table", false, out property);

    if (((property == null) || (property.Value == null)) || (((tableName = property.Value as string) == null) || string.IsNullOrEmpty(tableName)))
    {
        tableName = e.Name;
    }

    StringBuilder sql = new StringBuilder("CREATE TABLE ");
    sql.AppendFormat("`{0}`(", tableName);
    
    ..............
[4 Aug 2011 15:43] Fernando Gonzalez.Sanchez
Thank you for your bug report. This issue has been committed to our source repository of that product and will be incorporated into the next release.

If necessary, you can access the source repository and build the latest available version, including the bug fix. More information about accessing the source trees is available at

    http://dev.mysql.com/doc/en/installing-source.html

This has been fixed & committed already as part of http://bugs.mysql.com/bug.php?id=61230.

To be released at 6.4.4 and 6.3.8.