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

java - WARN : org.springframework.web.servlet.PageNotFound - No mapping found for HTTP request with URI [/board/] in DispatcherServlet with name 'appServlet' -

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

android - How to create dynamically Fragment pager adapter -