开发者

Linq to SQL Chunked Delete or Update Operation?

I have a lot of rows to delete in a table, and using ADO.NET I might send a SqlCommand with this text:

 WHILE(1=1)  
BEGIN  
DELETE TOP(5000) FROM myTable WHERE myval=123  
 IF @@ROWCOUNT < 5000 BREAK  
END  

I would wrap that in a transaction or 2 and could t开发者_运维问答hen delete in chunks so the DB could come up for air.

I would like to do the same thing but in C# using LINQ-to-SQL, is that possible?

Thanks.


Unfortunately, there is no mass update or mass delete operations in Linq-to-SQL (and with developement suspended on L2S, it's unlikely there ever will be)

The best you could do is

db.myTable.DeleteOnSubmit(db.MyTable.Where(m=>m.myval ==123).Take(5000));

But I'm pretty sure that will generate a SELECT followed by 5000 DELETE statements.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜