I am facing one issue while updating entity with some of the fields updating from original entity. Code is like below
public int SaveUser(UserDetail objUserDet)
{
DBEntities context = new DBEntities();
UserDetail userDetail = (from u in context.UserDetails.Where(u => 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();
}
But it gives me an error like
Attaching an entity of type failed because another entity of the same type already has the same primary key value.
How to update one entity with another is present with same primary key.