I am getting the following error when trying to attach an object that is already attached to a given context via context.AttachTo(...):
A
This does not directly answer OPs question but this is how I solved mine.
This is for those who are using DbContext instead of ObjectContext.
public TEntity Retrieve(object primaryKey)
{
return DbSet.Find(primaryKey);
}
DbSet.Find Method:
Finds an entity with the given primary key values. If an entity with the given primary key values exists in the context, then it is returned immediately without making a request to the store. Otherwise, a request is made to the store for an entity with the given primary key values and this entity, if found, is attached to the context and returned. If no entity is found in the context or the store, then null is returned.
Basically, it returns the attached object of the given primaryKey so you just need to apply the changes on the returned object to keep the right instance.