开发者

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.


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.


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜