Page 1 of 1

trouble using Table<TEntity>.Attach Method (TEntity,TEntity)

Posted: Thu 14 Oct 2010 11:29
by muthu
You should be able to use Linq Table.Attach method(s) to update the table with a disconnected object, however I have not been able to figure out a way for this to work without getting a "Cannot add an entity with a key that is already in use" exception.

Posted: Thu 14 Oct 2010 11:56
by AndreyR
I recommend you to use the following approach:
1. Try to select the entity by ID from the context.
2. If it is present, use the attach method with this loaded entity as an Original.
3. If there is no such entity, attach the entity without the Original parameter.