How to update a number of Rows in a Table using Linq -


i using following code update usersession column of activities. following code return records if expirytimestamp less current date. update usersession column 0 returned recods in table. .now wants if there 100 records returned these should update @ 1 time instead of using foreach. posible in linq

cachedatadatacontext db = new cachedatadatacontext();                 var data = (from p in db.activities                             p.expirytimestamp < datetime.now                             select p).tolist();                 data.foreach(ta => ta.usersession = "0");                 db.submitchanges(); 

in short, no: linq-2-sql not batch updates out of box.

(i not sure foreach work wrote - not think - similar , work)

foreach (var x in data) {x.usersession = "0";} db.submitchanges() 

but, if this, linq-2-sql send update statement each record database. example of 100 records returned 100 individual updates send database.


Comments

Popular posts from this blog

linux - Using a Cron Job to check if my mod_wsgi / apache server is running and restart -

actionscript 3 - TweenLite does not work with object -

jQuery Ajax Render Fragments OR Whole Page -