Skip to content

Instantly share code, notes, and snippets.

@yeurch
Last active December 15, 2015 12:39
Show Gist options
  • Select an option

  • Save yeurch/5261896 to your computer and use it in GitHub Desktop.

Select an option

Save yeurch/5261896 to your computer and use it in GitHub Desktop.
Running a set of statements in an Entity Framework migration (this particular example is in relation to https://github.com/davidfowl/JabbR/issues/751)
using System.Data.Entity.Migrations;
using System;
public partial class ChangeIndexingOnChatMessages : DbMigration
{
private static readonly string[] Statements = new[] {
"alter table dbo.ChatMessages drop constraint PK_ChatMessages",
"create clustered index CX_ChatMessages_When on dbo.ChatMessages ([When])",
"alter table dbo.ChatMessages add constraint PK_ChatMessages primary key nonclustered ([Key])"
};
public override void Up()
{
foreach (var statement in Statements)
Sql(statement);
}
public override void Down()
{
// Create a similar set of statements to reverse the index changes
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment