开发者

Linq to SQL Chunked Delete or Update Operation?

开发者 https://www.devze.com 2023-01-10 03:56 出处:网络
I have a lot of rows to delete in a table, and using ADO.NET I might send a SqlCommand with this text:

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

精彩评论

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