Entity framework Azure-代码优先迁移无法正常工作

Entity framework Azure-代码优先迁移无法正常工作,entity-framework,azure,azure-sql-database,azure-mobile-services,entity-framework-migrations,Entity Framework,Azure,Azure Sql Database,Azure Mobile Services,Entity Framework Migrations,我正在尝试通过代码优先迁移(如上所述)为我的azure应用程序创建一个sql server db架构 “我的表”的基本创建工作正常,但是azure(entitydata)特定的东西却不能。CreatedAt没有默认值,没有UpdatedAt触发器,聚集索引也有问题。我所有的桌子都会这样。这就是我正在做的(显示1表帐户的问题): my DBMigration类中的up方法如下所示: CreateTable( "dbo.Accounts", c =&g

我正在尝试通过代码优先迁移(如上所述)为我的azure应用程序创建一个sql server db架构

“我的表”的基本创建工作正常,但是azure(entitydata)特定的东西却不能。CreatedAt没有默认值,没有UpdatedAt触发器,聚集索引也有问题。我所有的桌子都会这样。这就是我正在做的(显示1表帐户的问题):

my DBMigration类中的up方法如下所示:

CreateTable(
            "dbo.Accounts",
            c => new
                {
                    Id = c.String(nullable: false, maxLength: 128),
                    Username = c.String(nullable: false, maxLength: 30),
                    Salt = c.Binary(),
                    SaltedAndHashedPassword = c.Binary(),
                    MailAddress = c.String(),
                    FacebookId = c.String(),
                    Version = c.Binary(nullable: false, fixedLength: true, timestamp: true, storeType: "rowversion"),
                    CreatedAt = c.DateTimeOffset(nullable: false, precision: 7),
                    UpdatedAt = c.DateTimeOffset(precision: 7),
                    Deleted = c.Boolean(nullable: false),
                })
            .PrimaryKey(t => t.Id)
            .Index(t => t.CreatedAt, clustered: true);

我认为EntityTableSqlGenerator应该做这些特定于azure的事情,但它似乎什么也没有改变。

我几天前遇到了同样的问题,并按照下面的描述暂时解决了它:我认为Microsoft EF团队应该永久解决它

根据我的临时解决方案,您需要在执行迁移文件之前进行一些修改

  • 首先,您需要取消从EntityData基类继承的所有实体的CreatedAt属性的聚集索引贴花

  • Id、CreatedAt和Deleted字段需要用默认值声明修饰

  • 可以在迁移文件中的每个create命令下面添加以下行


    您可以从

    中获得更多想法您是否确保您的本地webconfig文件指向Azure中的SQL数据库?默认情况下,它将指向localDB。如果这不是问题所在,那么如果表已经存在,是否会产生影响?
    CreateTable(
                "dbo.Accounts",
                c => new
                    {
                        Id = c.String(nullable: false, maxLength: 128),
                        Username = c.String(nullable: false, maxLength: 30),
                        Salt = c.Binary(),
                        SaltedAndHashedPassword = c.Binary(),
                        MailAddress = c.String(),
                        FacebookId = c.String(),
                        Version = c.Binary(nullable: false, fixedLength: true, timestamp: true, storeType: "rowversion"),
                        CreatedAt = c.DateTimeOffset(nullable: false, precision: 7),
                        UpdatedAt = c.DateTimeOffset(precision: 7),
                        Deleted = c.Boolean(nullable: false),
                    })
                .PrimaryKey(t => t.Id)
                .Index(t => t.CreatedAt, clustered: true);