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

Popular posts from this blog

python - Subclassed QStyledItemDelegate ignores Stylesheet -

java - HttpClient 3.1 Connection pooling vs HttpClient 4.3.2 -

SQL: Divide the sum of values in one table with the count of rows in another -