title: How do I use a transaction in LINQ to SQL using stored procedures?
body: <p>I have a piece of code that looks something like this (ClearImportTable and InsertPage are stored procedures):</p>
  
  <pre><code>datacontext.ClearImportTable() //Essentially a DELETE FROM table
  for (int i = 1; i &lt; MAX_PAGES; ++i){
      datacontext.InsertPage(i); //Inserts data into the table
  }
  </code></pre>
  
  <p>This is a somewhat simplified version of my code, but the idea is that it clears the table before inserting records.  The only problem is that if an error occurrs after ClearImportTable, all of the data from the table is wiped.  Is there any way to wrap this in a transaction so that if there are any errors, everything will be put back the way it was?</p>