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
Post a Comment