This article is a mirror article of machine translation, please click here to jump to the original article.

View: 21862|Reply: 0

[Source] Linq to SQL efficiency issues for deleting or emptying tables

[Copy link]
Posted on 8/1/2015 3:32:27 PM | | |

Today in the project you need to delete all the data in a table, or delete all the data id="XXX"

Use code like this:

                MAList = ctx. T_Info_MAs.Where(c => c.StockCode == stockcode). ToList();
                ctx. T_Info_MAs.DeleteAllOnSubmit(MAList);
                ctx. SubmitChanges();



It was found that the deletion speed was extremely slow, and there was a lot of useless work (taking out the list of elements that needed to be deleted), which was unbearable at 300,000 in terms of data volume

Therefore, the following methods are adopted:

ctx. ExecuteCommand("DELETE FROM T_Info_MA WHERE [STOCKCODE]=" + stockcode);


If you need to clear a table, you can use it directly:

ctx. ExecuteCommand("TRUNCATE TABLE T_Info_MA");




Previous:c# DateTime is a solution to get the day by specifying the date
Next:jquery displays the current system date and time in real time
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com