I have 2 related database tables which in simplified form look like this
Product(
product_id,
name
)
ProductSpecs(
spec_id,
product_id,
name,
value
)
Foreign key is set via product_id field and ProductSpecs table has a unique constraint on (product_id, name) pair.
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.
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.
Then I call DataContext.SubmitChanges() and get an error that my unique constraint was violated.
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).
What is the reason of this behavior and how to fix or workaround it?
Thanks.