title: How to update one entity if another is in use in Entity framework
body: <p>I am facing one issue while updating entity with some of the fields updating from original entity. Code is like below</p>
  
  <pre><code> public int SaveUser(UserDetail objUserDet)
      {
       DBEntities context = new DBEntities();
       UserDetail userDetail = (from u in context.UserDetails.Where(u =&gt; u.UserDetID == objUserDet.UserDetID)
                                           select u).Single();
       objUserDet.UserId = userDetail.UserId;
       //context.UserDetails.ApplyCurrentValues(objUserDet); //For ObjectContext works fine.
       context.UserDetails.Attach(objUserDet);
       context.Entry(objUserDet).State = EntityState.Modified;
       context.SaveChanges();
      }
  </code></pre>
  
  <p>But it gives me an error like </p>
  
  <p><strong>Attaching an entity of type failed because another entity of the same type already has the same primary key value.</strong></p>
  
  <p>How to update one entity with another is present with same primary key.</p>