Brian Hooper
Brian Hooper

Reputation: 22054

DeleteAllOnSubmit not deleting anything

I am using DeleteAllOnSubmit to remove rows from a table, like this:-

Try

    Using ts As TransactionScope = New TransactionScope

        Dim db As MyDataContext = New MyDataContext

        db.my_tables.DeleteAllOnSubmit(From a In db.my_tables
                                           Where a.col1 = given_col1 AndAlso
                                                 a.col2 = given_col2 AndAlso
                                                 a.col3 = given_col3)

        db.SubmitChanges

    End Using

Catch ex As Exception
    ' Log an exception if it occurs
End Try

but when I do this, no rows are removed. I have checked that the selection criteria are correct by listing the rows, just before the DeleteAllOnSubmit, thus:-

Dim rows_to_go As List(Of my_table) = (From a In db.my_tables
                                           Where a.col1 = given_col1 AndAlso
                                                 a.col2 = given_col2 AndAlso
                                                 a.col3 = given_col3)).ToList

and inspecting the contents of rows_to_go in debug, which shows that some rows are selected by the criteria, but inspection of the table with SQL Server Management Studio shows the same rows before and after. No exception is thrown.

Does anyone know why this call is so ineffective, and what I should do about it?

Upvotes: 2

Views: 190

Answers (1)

usr
usr

Reputation: 171218

You have to commit the transaction scope:

ts.Complete();

It did it's work by rolling back.

Upvotes: 2

Related Questions