Bug #68237 property engine can not be set on table with codefirst way
Submitted: 1 Feb 2013 2:55
Reporter: Akini Xu Email Updates:
Status: Open Impact on me:
None 
Category:Connector / NET Severity:S4 (Feature request)
Version:6.6.4 OS:Windows
Assigned to: CPU Architecture:Any

[1 Feb 2013 2:55] Akini Xu
Description:
mysql 5.5.28
.net connector 6.6.4
vs2012 c#

I would like to create a table with engine MyISAM with Code First(Entity Framework). 

in migrations.cs
public override void Up()
{
  CreateTable(
    "Tests",
    c => new
          {
              ID = c.Int(nullable: false),
              Name = c.String(unicode: false),
          }, new { Engine = "MyISAM" })
    .PrimaryKey(t => t.ID);
}
after update-database 
the table's engine is InnoDB.
i just want change InnoDB to MyISAM with code first.

How to repeat:
create table with code first and use "add-migration xxx; update-database -verbose" 

Suggested fix:
modify the source code.
Project: MySql.Data.Entity.csproj
File: MySqlMigrationSqlGenerator.cs
Void: protected virtual MigrationStatement Generate(CreateTableOperation op)
old:
    protected virtual MigrationStatement Generate(CreateTableOperation op)
    {
      StringBuilder sb = new StringBuilder();
      if (generatedTables == null)
        generatedTables = new List<string>();

      if (!generatedTables.Contains(op.Name))
      {
        generatedTables.Add(op.Name);
      }
      sb.Append("create table " + "`" + op.Name + "`" + " (");

      //columns
      sb.Append(string.Join(",", op.Columns.Select(c => "`" + c.Name + "` " + Generate(c))));

      if (op.PrimaryKey != null && !sb.ToString().Contains("primary key"))
      {
        sb.Append(",");
        sb.Append("primary key ( " + string.Join(",", op.PrimaryKey.Columns.Select(c => "`" + c + "`")) + ") ");
      }

      sb.Append(") engine=InnoDb auto_increment=0");
      

      return new MigrationStatement() { Sql = sb.ToString() };
    }

new:
    protected virtual MigrationStatement Generate(CreateTableOperation op)
    {
      StringBuilder sb = new StringBuilder();
      if (generatedTables == null)
        generatedTables = new List<string>();

      if (!generatedTables.Contains(op.Name))
      {
        generatedTables.Add(op.Name);
      }
      sb.Append("create table " + "`" + op.Name + "`" + " (");

      //columns
      sb.Append(string.Join(",", op.Columns.Select(c => "`" + c.Name + "` " + Generate(c))));

      if (op.PrimaryKey != null && !sb.ToString().Contains("primary key"))
      {
        sb.Append(",");
        sb.Append("primary key ( " + string.Join(",", op.PrimaryKey.Columns.Select(c => "`" + c + "`")) + ") ");
      }

      if (op.AnonymousArguments.ContainsKey("Engine"))
      {
          sb.Append(string.Format(") engine={0} auto_increment=0", op.AnonymousArguments["Engine"]));
      }
      else
      {
          sb.Append(") engine=InnoDb auto_increment=0");
      }
      

      return new MigrationStatement() { Sql = sb.ToString() };
    }