EF - Update multiple rows in database without using foreach loop
Just to update Steve's answer, in newer EF (current EF Core 3.1.3) you can do it all as one statement.
await db.Message.Where(m => m.FromUser == fromUser && m.ToUser == toUser).ForEachAsync(m => m.IsRead = true);
await db.SaveChangesAsync().ConfigureAwait(false);
You don't need to SaveChanges() on each iteration. That will hit the database multiple times. Try:
using (var db = new MyDbContext())
{
string fromUser = ""; //sender
string toUser = ""; //receiver
var messages = db.Message.Where(x => x.FromUser == fromUser && x.ToUser == toUser)
.ToList();
messages.ForEach(m => m.IsRead = true);
db.SaveChanges();
}