title: Asp.net Identity 2.0 update user
body: <p>Having a problem with saving user changes to the database, like changing the person's name.  I'm using the IdentityModel that is automatically created in a new VS2013 web project using individual authentication.  Sadly, the template doesn't allow you to change any user information, other than changing roles.  I'm looking around via google, I haven't found much.  Anyone implement updating using the base identity code?</p>
  
  <p>This is the closest thing I found:</p>
  
  <p><a href="https://stackoverflow.com/questions/20444022/updating-user-data-asp-net-identity">Updating user data - Asp.net Identity</a></p>
  
  <p>I haven't been successful at incorporating default template. I've just started using Identity this week, so it might be my lack of understanding that's the problem.</p>
  
  <pre><code>var updatedUser = new ApplicationUser
              {
                  Id = model.UserId,
                  UserName = model.UserName,
                  CustomerId = model.CustomerId,
                  Email = model.EmailAddress,
                  FirstName = model.FirstName,
                  LastName = model.LastName,
                  PhoneNumber = model.PhoneNumber,                    
              };
  
  ...
  var result = await UserManager.UpdateAsync(updatedUser);
  </code></pre>
  
  <p>My UserManager is created like this:</p>
  
  <pre><code>return _userManager ?? HttpContext.GetOwinContext().GetUserManager&lt;ApplicationUserManager&gt;();
  </code></pre>
  
  <p>I get the following error in the browser:</p>
  
  <p>Attaching an entity of type 'ApplicationUser' failed because another entity of the same type already has the same primary key value. This can happen when using the 'Attach' method or setting the state of an entity to 'Unchanged' or 'Modified' if any entities in the graph have conflicting key values. This may be because some entities are new and have not yet received database-generated key values. In this case use the 'Add' method or the 'Added' entity state to track the graph and then set the state of non-new entities to 'Unchanged' or 'Modified' as appropriate</p>
  
  <p>Thanks</p>