title: MVC 5 Updating multiple fields of one row in database
body: <p>I'm practicing MVC 5 and in my application I have a controller method that should update address info for a given user profile.</p>
  
  <p>I do this by accessing the database with a context object, and my first thought was to copy the database row to an object, make the changes and then put it back using the <code>AddOrUpdate()</code> method. However, I only see an <code>Add()</code> method.</p>
  
  <p>So instead I did the following:</p>
  
  <pre><code>public ActionResult EditBillingDetails(EditBillingDetailsViewModel model)
  {
      if (ModelState.IsValid)
      {
          string id = User.Identity.GetUserId();
          ApplicationDbContext db = new ApplicationDbContext();
  
          db.Users.Single(u =&gt; u.Id == id).FirstName = model.FirstName;
          db.Users.Single(u =&gt; u.Id == id).LastName = model.LastName;
          db.Users.Single(u =&gt; u.Id == id).Email = model.Email;
          db.Users.Single(u =&gt; u.Id == id).Address = model.Address;
          db.Users.Single(u =&gt; u.Id == id).City = model.City;
          db.Users.Single(u =&gt; u.Id == id).ZIP = model.ZIP;
          db.Users.Single(u =&gt; u.Id == id).Country = model.Country;
  
          db.SaveChanges();
  
          return RedirectToAction("Manage", new { Message = ManageMessageId.ChangeBillingSuccess });
      }
      return View(model);
  }
  </code></pre>
  
  <p>Which works just fine, but it feels wrong to go look up the same entry 7 times just to update each field one by one. Isn't there a better way to do this? </p>