0

I am trying to initially create a sql server db schema for my azure application with code first migrations (as described here).

The basic creation of my tables works, however the azure (entitydata) specific things don't. There is no default value for CreatedAt, no UpdatedAt Trigger and also a problem with a clustered index. This happens to all of my tables. Thats what i am doing (shows the problem for 1 Table Account):

 public Configuration()
 {
        AutomaticMigrationsEnabled = false;
        SetSqlGenerator("System.Data.SqlClient", new EntityTableSqlGenerator());
 }


var migrator = new DbMigrator(new Configuration());
migrator.Update();

The up-Method in my DBMigration-Class looks as follows:

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);

I thought, that the EntityTableSqlGenerator should do these azure specific things, however it seems that it changes nothing.

DominikP
  • 151
  • 1
  • 10
  • Have you ensured that your local webconfig file is pointing your SQL database in Azure? By default, it will point to a localDB. If that's not the issue, does it make a difference if the table existed already? – lindydonna Oct 06 '15 at 03:31

1 Answers1

0

I had the same issue few days ago and solved it temporarily as described below: I think Microsoft EF team should solve it permanently.

According to my temporary solution, you need to make some modifications before execute your migration file.

  1. First, you need to cancel clustered index decalarations for CreatedAt properties for all entities which is inheriting from EntityData base class.

  2. Id, CreatedAt and Deleted fields need to be decorated with default value declarations.

You can add following lines below each create commands in your migration files.

enter image description here

You can get additional ideas from here

Community
  • 1
  • 1
aog
  • 484
  • 3
  • 14