Do not use the ToList()
method as in the accepted answer !
Running SQL profiler, I verified and found that ToList()
function gets all the records from the database. It is really bad performance !!
I would have run this query by pure sql command as follows:
string query = "Update YourTable Set ... Where ...";
context.Database.ExecuteSqlCommandAsync(query, new SqlParameter("@ColumnY", value1), new SqlParameter("@ColumnZ", value2));
This would operate the update in one-shot without selecting even one row.