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

使用EF 6 alpha3 Code First部署到SQL Azure时出错,并且创建__MigrationHistory表的迁移,第1张

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

这是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);    }}

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

internal sealed class Configuration : DbMigrationsConfiguration<MyContext> {    public Configuration()    {        AutomaticMigrationsEnabled = true;        SetSqlGenerator("System.Data.SqlClient", new AzureSqlGenerator());    }    protected override void Seed(MyContext context)    {    }}


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/zaji/5675441.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-12-16
下一篇 2022-12-17

发表评论

登录后才能评论

评论列表(0条)

保存