使用EF 6 alpha3 Code First和迁移创建__MigrationHistory表时,部署到SQL Azure时出错

Bru*_*cão 3 entity-framework entity-framework-6 azure-sql-database

我首先使用的是EF 6 alpha 3代码.当我尝试在运行Update-Database命令的SQL Azure上创建数据库时,出现以下错误:

此版本的SQL Server不支持没有聚簇索引的表.请创建聚簇索引,然后重试.

我将错误跟踪到__MigrationHistory表创建sql命令.

CREATE TABLE [dbo].[__MigrationHistory] (
    [MigrationId] [nvarchar](255) NOT NULL,
    [ContextKey] [nvarchar](512) NOT NULL,
    [Model] [varbinary](max) NOT NULL,
    [ProductVersion] [nvarchar](32) NOT NULL,
    CONSTRAINT [PK_dbo.__MigrationHistory] PRIMARY KEY NONCLUSTERED ([MigrationId], [ContextKey])
)
Run Code Online (Sandbox Code Playgroud)

任何人都知道如何解决这个问题?

谢谢,

And*_*ers 13

这是Alpha 3中的一个错误 - 很抱歉给您带来不便.

有一个非常简单的解决方法:

1)创建自定义迁移SQL生成器:

public class AzureSqlGenerator : SqlServerMigrationSqlGenerator
{
    protected override void Generate(CreateTableOperation createTableOperation)
    {
        if ((createTableOperation.PrimaryKey != null)
            && !createTableOperation.PrimaryKey.IsClustered)
        {
            createTableOperation.PrimaryKey.IsClustered = true;
        }

        base.Generate(createTableOperation);
    }
}
Run Code Online (Sandbox Code Playgroud)

2)在迁移配置中注册自定义生成器:

internal sealed class Configuration : DbMigrationsConfiguration<MyContext> 
{
    public Configuration()
    {
        AutomaticMigrationsEnabled = true;

        SetSqlGenerator("System.Data.SqlClient", new AzureSqlGenerator());
    }

    protected override void Seed(MyContext context)
    {
    }
}
Run Code Online (Sandbox Code Playgroud)