We have our migrations, and we have a seed method that executes after every migration is run.
If the seed method fails, I can rollback the seed data but I also want to, in code, rollback the "update-database" statement to restore the db structure to what it was prior.
Is this possible?
Some code:
internal sealed class Configuration : DbMigrationsConfiguration<TheContext>
{
protected override void Seed(TheContext context)
{
//Set a bunch of entities
using (var transaction = new TransactionScope())
{
try
{
context.SaveChanges();
transaction.Complete();
}
catch (Exception ex)
{
//TODO: How do I rollback the last Update-Database command?
throw;
}
}
}