title: Efficient way of updating list of entities
body: <p>I am working on a project which allows the user to edit a list of entities. I map these entities to view models and display them with editor fields. When the user presses the submit button, I go through each model and update it like so:</p>
  
  <pre><code>foreach (var viewModel in viewModels)
  {
      //Find the database model and set the value and update
      var entity = unit.EntityRepository.GetByID(fieldModel.ID);
      entity.Value = viewModel.Value;
      unit.EntityRepository.Update(entity);
  }
  </code></pre>
  
  <p>The above code works, however as you can see we need to hit the database twice for every entity (once to retrieve and another to update). Is there a more efficient way of doing this using Entity Framework? I noticed that each update generates a separate SQL statement. Is there a way of committing all the updates after the loop has finished?</p>