title: Linq to SQL: execution order when calling SubmitChanges()
body: <p>I have 2 related database tables which in simplified form look like this</p>
  
  <pre><code>Product(
    product_id,
    name
  )
  
  ProductSpecs(
    spec_id,
    product_id,
    name,
    value
  )
  </code></pre>
  
  <p>Foreign key is set via product_id field and ProductSpecs table has a unique constraint on (product_id, name) pair.</p>
  
  <p>Now in my ASP.NET MVC application when user edits product specs and saves the data I delete old specs and insert all as new ones. </p>
  
  <p>I do this by first calling DataContext.DeleteAllOnSubmit() and providing current (old) ProductSpecs as a parameter, and then I add new specs to the Product.ProductSpecs collection.</p>
  
  <p>Then I call DataContext.SubmitChanges() and get an error that my unique constraint was violated.</p>
  
  <p>By looking at the SQL statements returned by DataContenxt.GetChangeText() I can see that INSERTs are executed before DELETEs (even though I called DeleteAllOnSubmit() before Add).</p>
  
  <p>What is the reason of this behavior and how to fix or workaround it?</p>
  
  <p>Thanks.</p>