title: EF - Update multiple rows in database without using foreach loop
body: <p>My test code:</p>
  
  <pre><code>using (var db = new MyDbContext())
  {
    string fromUser = ""; //sender
    string toUser = ""; //receiver
  
    var messages = db.Message.Where(x =&gt; x.FromUser == fromUser &amp;&amp; x.ToUser == toUser)
                   .ToList();
  
    foreach (var message in messages)
    {
      message.IsRead = true;
      db.SaveChanges();
    }
  }
  </code></pre>
  
  <p>My question: is there another way to update database without using <code>foreach</code> loop in that case?</p>
  
  <p>p/s: I'd been reference these questions but all of them didn't solve my problem:</p>
  
  <ul>
  <li><p><a href="https://stackoverflow.com/questions/18830113/update-multiple-rows-in-datatable-without-loop">Update multiple rows in datatable without loop</a></p></li>
  <li><p><a href="https://stackoverflow.com/questions/16663756/updating-multiple-records-in-database-with-linq-to-sql-without-loop-is-it-possi">updating multiple records in database with linq to sql without loop, is it possible?</a></p></li>
  <li><p><a href="https://stackoverflow.com/questions/27407910/update-multiple-rows-without-looping">Update multiple rows without looping</a></p></li>
  </ul>