sql >> Database teknologi >  >> RDS >> Mysql

EF6 MySql:Update-Database -Script genererer SQL uden semikolon

Du kan opnå dette ved at udvide MySqlMigrationSqlGenerator som følger:

/// <summary>
/// Custom MigrationSqlGenerator to add semi-colons to the end of 
/// all migration statements.
/// </summary>
public class CustomMySqlMigrationSqlGenerator : MySqlMigrationSqlGenerator {
    public override IEnumerable<MigrationStatement> Generate(IEnumerable<MigrationOperation> migrationOperations, string providerManifestToken) {
        IEnumerable<MigrationStatement> statements = base.Generate(migrationOperations, providerManifestToken);
        foreach (MigrationStatement statement in statements) {
            if (!statement.Sql.EndsWith(";")) {
                statement.Sql = statement.Sql.TrimEnd() + ";";
            }
        }
        return statements;
    }
}

Og aktiver det i Configuration.cs :

public Configuration() {
    AutomaticMigrationsEnabled = false;
    SetSqlGenerator("MySql.Data.MySqlClient", new CustomMySqlMigrationSqlGenerator());
}



  1. MySQL-korreleret underforespørgsel i JOIN-syntaks

  2. SQL Server-svarende til WM_CONCAT-funktionen

  3. Vælg særskilte poster på en joinforbindelse

  4. Entity Framework MySQL tinyint(1) System.Boolean.Parse FormatException