Adding ROWGUIDCOL to Entity Framework Code First using migrations

To add add a ROWGUIDCOL to a unique identifier in a table using code first you have to use code migrations.

Below is the snippet you need. I haven’t covered how to perform a migration because there are plenty of articles available.

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
public partial class AddRowGuidCol : DbMigration
{
   public override void Up()
   {
      Sql("ALTER TABLE dbo.Address ALTER COLUMN [AddressID] ADD ROWGUIDCOL");
   }

   public override Void Down()
   {
      Sql("ALTER TABLE dbo.Address ALTER COLUMN [AddressID] DROP ROWGUIDCOL");
   }
}
comments powered by Disqus

Related