简体   繁体   中英

Linq to SQL insert many rows in one SubmitChanges()

I'm inserting to table 1000 rows in one SubmitChanges() call is faster and i must put to this table many terabytes of rows.

One of this will be insterted successfully other will return an exception in inserting. How to calculate how many exceptions we have and how to catch them exclusive for every row?

Well, unfortunately linq2sql is not at all suitable for batch insertions. It is slow so you really want to look at a different solution. You could validate all records before insertion and then use sqlbulkcopy for a very fast insert.

If it's throwing on the SubmitChanges() then there's not much you can do. Either wrap it in a try-catch to at least grab some of the exceptions. Or, if you really need to know row by row exceptions, you'll have to insert them individually.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM