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();
}
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…