title: LINQ and handling rollbacks
body: <p>I have an image upload handler (.ASHX). I am storing image meta data in the database and am naming the image from the id of that entry into the database. I am using LINQ and getting the ID back after I call SubmitChanges. Then I use that id to save the image. I obviously want to rollback the insert if the File.SaveAs fails. Is my code below correct?</p>
  
  <pre><code>using (UserDataContext userDataContext = new UserDataContext())
  {
      GalleryImage galleryImage = new GalleryImage();
      galleryImage.metaName = "some meta stuff";
      userDataContext.GalleryImages.InsertOnSubmit(galleryImage);
      System.Data.Common.DbTransaction transaction = userClassContext.Transaction;
      userDataContext.SubmitChanges();
      try
      {
          string targetPath = "somepath/" + galleryImage.Id;
          file.SaveAs(targetFilePath);
      }
      catch
      {
          transaction.Rollback();
      }
  }
  </code></pre>
  
  <p>Thanks</p>