c# - Using Linq, I need to delete all of the rows from a table and then enter about a thousand new rows. How can I make this whole thing a transaction? -


i need empty table , enter around 1000 rows it. need whole thing transaction, however, i'm not stuck empty (or partially empty) table if of inserts fail.

so experimented code below, insert (.add) intentionally fail. when running it, however, call delete stored procedure (prdeletefromusertable) not roll transaction. i'm left empty table , no inserts.

using (var context = new entities(_strconnection)) {     using (var transaction = new transactionscope())     {         //delete rows in table         context.prdeletefromusertable();          //add row, made intentionally make fail test transaction         context.usertable.add(row);         context.savechanges();          //end transaction         transaction.complete();     } }   

how accomplish using linq-to-sql?

linq queries (language integrated query) , not designed bulk deletion , insertion. solution use sql delete rows delete mytable , sqlbulkcopy 1000 inserts.


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -