Jeremy Boyd
Jeremy Boyd

Reputation: 5405

How does Linq to SQL do DeleteAllOnSubmit?

I don't want to know how to do it, I want to know the underlying code. Every google query comes up as a tutorial on how to delete from the database.

Upvotes: 0

Views: 2225

Answers (2)

O'Rooney
O'Rooney

Reputation: 3100

As Randy says, it does indeed issue individual SQL deletes for each entity :( This is obviously very inefficient compared to a single SQL "delete where"... therefore, it seems, people write SQL and pass it through to ExecuteCommand instead.

Alternatively, you can use the DeleteBatch extensions discussed here: http://www.aneyfamily.com/terryandann/post/2008/04/Batch-Updates-and-Deletes-with-LINQ-to-SQL.aspx

Upvotes: 1

Randy Minder
Randy Minder

Reputation: 48452

It's not clear what exactly you mean. But I'll take a stab at it. For each entity you want to delete, L2S issues a single T-SQL Delete statement to delete the entity. Therefore, if you are deleting say 20 entities, 20 Delete statements will be issued to SQL Server.

Upvotes: 1

Related Questions