Created
November 26, 2013 10:48
-
-
Save diffused/7656467 to your computer and use it in GitHub Desktop.
Delete all data from DB except the dbo._MigrationHistory table using Entity Framework.
This file contains 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(var context = new PlayContext()) | |
{ | |
context.Database.ExecuteSqlCommand(@" | |
EXEC sp_MSForEachTable 'ALTER TABLE ? NOCHECK CONSTRAINT ALL'; | |
EXEC sp_MSForEachTable 'IF OBJECT_ID(''?'') NOT IN (OBJECT_ID(''[dbo].[__MigrationHistory]'')) DELETE FROM ?'; | |
EXEC sp_MSForEachTable 'ALTER TABLE ? WITH CHECK CHECK CONSTRAINT ALL'; | |
"); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment