Update Multiple Row using Linq

some time it requires to update multiple record using linq , for selecting single value you have to use Dirstdefault() , but for selecting multiple value you have to use list like below

var userId=Convert.ToInt32(outuserId.Value);
var res = context.tblCarts.Where(i => i.Cookies_Id == Cartcokie.Value).ToList();
res.ForEach(a => a.User_Id = userId);
context.SaveChanges();

 

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>