title: update list from another list - entity framework
body: <p><strong>Room Model</strong></p>
  
  <pre><code>public class Room
  {
      public int Id { get; set; }
      public string Name { get; set; }
      public string Address { get; set; }
  }
  </code></pre>
  
  <p><code>Id</code> is the primary key here</p>
  
  <p>As in entity framework, all the room details are in the dbcontext</p>
  
  <pre><code>dbContext.Rooms
  </code></pre>
  
  <p>And there is a <code>IList&lt;Room&gt; updateRooms</code>with list of updated name and address for few rooms.</p>
  
  <p>How do I update <code>dbContext.Rooms</code> for the matching items in <code>updateRooms</code> using the primary key <code>Id</code> and save to DB using entity framework.</p>
  
  <p><strong>Note:</strong> I do understand that I can update each Room in dbContext.Rooms and save as below</p>
  
  <pre><code>foreach (var room in updateRooms)
  {
      dbContext.Rooms.Attach(room);
      dbContext.Entry(room).State = EntityState.Modified;
      dbContext.SaveChanges();
  }
  </code></pre>
  
  <p>but is there a way <strong>attach all rooms</strong> and save at once</p>