tags:

views:

233

answers:

2

Using LINQ, when calling several deleteOnSubmit in a row then calling SubmitChanges:

DataContext.DeleteOnSubmit(itemFromTb1);
DataContext.DeleteOnSubmit(itemFromTb2);

DataContext.SubmitChanges();

Will they always be deleted in the order (itemFromTb1 then itemFromTb2) I called them or not necessarily?

Edit: I know the SubmitChanges() performs in the following order

  1. Insert
  2. Update
  3. Delete

But I'm not sure if each of those are performed in the order they were called.

A: 

It has been my experience they are deleted in the order in which you add them. You can verify this by examining the resulting SQL code that is generated, using the context Log property.

Randy Minder
Even if they are in the right order in the sql it might not guarantee they will always be. I can't seem to find any info on the delete order it might mean it's in a "logical" order so there is nothing to say about it.
DrDro
@DrDro - If you absolutely need to control the order, you'll probably have to do them one at a time, with a SubmitChanges() after each. If you need to do this within the scope of a transaction, you can use TransactionScope, which would wrap all SubmitChanges into a single transaction.
Randy Minder
A: 

It seems that nobody knows the official behaviour of SubmitChanges() in this case. I had a lot of "I think they are done in the same order" and did not find any article or offical info on it. It does not seem that many people had any problem with that so either everybody does a SubmitChanges() after each DeleteOnSubmit or we can rely on statistics :s to conclude that they are done in the order they were called.

DrDro