EntityFramework迁移在自定义SqlServerMigrationSqlGenerator中获取当前DbContext

时间:2016-06-30 11:39:54

标签: c# entity-framework entity-framework-6 database-migration ef-migrations

我有一个来自SqlServerMigrationSqlGenerator的自定义类。

public class CustomMigration : SqlServerMigrationSqlGenerator
{
    protected override void Generate(AlterColumnOperation alterColumnOperation)
    {
        // ....
        // ....
    }
}

在方法Generate中是否可以在当前数据库上执行sql命令来应用迁移?例如:

public class CustomMigration : SqlServerMigrationSqlGenerator
{
    protected override void Generate(AlterColumnOperation alterColumnOperation)
    {
        // I need to get the DATABASE CONTEXT HERE!!!
        // to execute a sql command
        var c = context.Database.ExecuteSqlCommand("SELECT DATABASEPROPERTYEX('MyDB', 'Collation')");
    }
}

谢谢!

0 个答案:

没有答案