Skip to content

Instantly share code, notes, and snippets.

@diffused
Created April 1, 2015 11:46
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save diffused/90d329ac8f2878c39661 to your computer and use it in GitHub Desktop.
Save diffused/90d329ac8f2878c39661 to your computer and use it in GitHub Desktop.
EF + Sql Server wipe data in all tables listed in __MigrationHistory
context.Database.ExecuteSqlCommand("sp_MSForEachTable 'ALTER TABLE ? NOCHECK CONSTRAINT ALL'");
context.Database.ExecuteSqlCommand("sp_MSForEachTable 'IF OBJECT_ID(''?'') NOT IN (ISNULL(OBJECT_ID(''[dbo].[__MigrationHistory]''),0)) DELETE FROM ?'");
context.Database.ExecuteSqlCommand("EXEC sp_MSForEachTable 'ALTER TABLE ? CHECK CONSTRAINT ALL'");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment