10

I found this article about how to insert, update and delete using linq pad but it mentions nothing about rolling back anything.

Is it possible to rollback in linqpad?

chobo2
  • 83,322
  • 195
  • 530
  • 832

1 Answers1

14

Yes. You can do:

using (TransactionScope scope = new TransactionScope()) {
  // Put the operations that you want to protect in a transaction here.

  if (you_want_to_commit) {
    scope.Complete();
  }
  // Otherwise, it'll roll back when you exit the using block.
}
sblom
  • 26,911
  • 4
  • 71
  • 95
  • How I understand Complete is if nothing crashes then no rollback is done. I want to do a commit but then a rollback right away even if everything went fine. So It would be basically like Begin Tran.... RollBack Tran in a sql query. – chobo2 Jul 03 '12 at 16:47
  • If you want to actually send to the server (even if you roll back later), you do a SubmitChanges() – Bertus van Zyl Jan 14 '19 at 05:44