c# - Update Multiple Rows in Entity Framework from a list of ids -
i trying create query entity framework allow me take list of ids , update field associated them.
example in sql:
update friends set msgsentby = '1234' id in (1, 2, 3, 4)
how convert above entity framework?
something below
var idlist=new int[]{1, 2, 3, 4}; using (var db=new somedatabasecontext()) { var friends= db.friends.where(f=>idlist.contains(f.id)).tolist(); friends.foreach(a=>a.msgsentby='1234'); db.savechanges(); }
update:
you can update multiple fields below
friends.foreach(a => { a.property1 = value1; a.property2 = value2; });
Comments
Post a Comment