Last active
December 15, 2015 12:39
-
-
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)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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