My test code:
using (var db = new MyDbContext())
{
string fromUser = ""; //sender
string toUser = ""; //receiver
var messages = db.Message.Where(x => x.FromUser == fromUser && x.ToUser == toUser)
.ToList();
foreach (var message in messages)
{
message.IsRead = true;
db.SaveChanges();
}
}
My question: is there another way to update database without using foreach
loop in that case?
p/s: I'd been reference these questions but all of them didn't solve my problem: