每次迭代都不需要SaveChanges().这将多次击中数据库.尝试:
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(); }