title: ef core update multiple items and then save
body: <p>I need to update multiple items in the database.</p>
  
  <p>My questions:</p>
  
  <ul>
  <li>do I need to use ctx.Items.Update(item); ?</li>
  <li>can I first update all the items in loop and then use ctx.SaveChangesAsync()?</li>
  </ul>
  
  <p>Basically I need to speed this up so I assume if I update the items properties and then call SaveChangesAsync() for all of them it will make one call to the database rather that doing it inside the loop for each item? </p>
  
  <p>What about the ctx.Items.Update(item)? does it make any sense having it? I think I need this otherwise how will it know what to update, right?</p>
  
  <pre><code>using (var ctx = new MyCOntext())
  {
       var allToBeUpdated = await ctx.Items.Where(t=&gt;t.ToBeUpdated == true).ToListAsync();
  
        foreach (var item in allToBeUpdated)
        {
              item.ToBeUpdated = false;
  
              ctx.Items.Update(item); // do I need this ?
        }
  
         await ctx.SaveChangesAsync();  // can I have the save changes async out of foreach? So I can update all the items at once rather than one by one
  }
  </code></pre>