I have two tables with a foreign key constraint how can I delete rows from both of them in one transaction? linq to SQL seems to call my deletes in the wrong order. Is there somewhere I can check and make sure the constraint is recognized properly by linq to SQL??
DataContext.OtherImages.DeleteOnSubmit(myOtherImage);
DataContext.Images.DeleteOnSubmit(myImage);
DataContext.SubmitChanges();
The Foreign key constraint is on OtherImages. Thanks!
You should have something like
in your Image class.
should work fine. My guess is that you’re forgetting about another foreign key. You can see what query is being run by doing
or something equivalent. I wouldn’t recommend cascading the deletes just to make this work since it should work without doing that.