Skip to content

Instantly share code, notes, and snippets.

@rqx110
Created December 1, 2016 02:15
Show Gist options
  • Save rqx110/fe3a2df4deacfcb4ac908260adf89d86 to your computer and use it in GitHub Desktop.
Save rqx110/fe3a2df4deacfcb4ac908260adf89d86 to your computer and use it in GitHub Desktop.
using MySql for ABP
public class CustomerMySqlMigrationSqlGenerator : MySqlMigrationSqlGenerator
{
public override IEnumerable<MigrationStatement> Generate(IEnumerable<MigrationOperation> migrationOperations, string providerManifestToken)
{
var otherMigrationOperations = new List<MigrationOperation>();
var statements = new List<MigrationStatement>();
foreach (var op in migrationOperations)
{
var migration = op as AlterTableOperation;
if (migration != null)
{
var sb = new StringBuilder();
sb.AppendFormat("alter table '{0}'", TrimSchemaPrefix(migration.Name));
statements.Add(new MigrationStatement { Sql = sb.ToString() });
}
else
{
otherMigrationOperations.Add(op);
}
}
statements.AddRange(base.Generate(otherMigrationOperations, providerManifestToken));
return statements;
}
private string TrimSchemaPrefix(string table)
{
if (table.StartsWith("dbo.") || table.Contains("dbo."))
return table.Replace("dbo.", "");
return table;
}
}
@rqx110
Copy link
Author

rqx110 commented Dec 1, 2016

  • Adding the DbConfigurationTypeAttribute on the context class:
    [DbConfigurationType(typeof(MySqlEFConfiguration))]

  • Adding Configuration.cs:

public Configuration()
{
  SetSqlGenerator("MySql.Data.MySqlClient", new CustomerMySqlMigrationSqlGenerator());
}

*maybe you should remove all default migration files, then add migration yourself

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment