I am getting the following error when trying to attach an object that is already attached to a given context via context.AttachTo(...):
context.AttachTo(...)
A
A simpler approach is:
bool isDetached = context.Entry(user).State == EntityState.Detached; if (isDetached) context.Users.Attach(user);