How can I stop Entity Framework 5 migrations adding dbo. into key names?

前端 未结 4 1117
情深已故
情深已故 2020-12-05 00:32

I started a project using Entity Framework 4.3 Code First with manual migrations and SQL Express 2008 and recently updated to EF5 (in VS 2010) and noticed that now when I ch

4条回答
  •  长情又很酷
    2020-12-05 01:12

    For Automatic Migrations use this code:

    public class MyOwnMySqlMigrationSqlGenerator : MySqlMigrationSqlGenerator
    {
        protected override MigrationStatement Generate(AddForeignKeyOperation addForeignKeyOperation)
        {
            addForeignKeyOperation.PrincipalTable = addForeignKeyOperation.PrincipalTable.Replace("dbo.", "");
            addForeignKeyOperation.DependentTable = addForeignKeyOperation.DependentTable.Replace("dbo.", "");
            MigrationStatement ms = base.Generate(addForeignKeyOperation);
            return ms;
        }
    }
    

    And Set it on configuration:

    SetSqlGenerator("MySql.Data.MySqlClient", new MyOwnMySqlMigrationSqlGenerator());
    

提交回复
热议问题