Created
December 1, 2016 02:15
-
-
Save rqx110/fe3a2df4deacfcb4ac908260adf89d86 to your computer and use it in GitHub Desktop.
using MySql for ABP
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Adding the DbConfigurationTypeAttribute on the context class:
[DbConfigurationType(typeof(MySqlEFConfiguration))]
Adding Configuration.cs:
*maybe you should remove all default migration files, then add migration yourself