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

Discussion of open issues, suggestions and bugs regarding ADO.NET provider for PostgreSQL
Post Reply
Posts: 10
Joined: Tue 28 Sep 2010 19:31

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

Post by muthu » Thu 14 Oct 2010 11:29

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.

Devart Team
Posts: 2919
Joined: Mon 07 Jul 2008 13:16

Post by AndreyR » Thu 14 Oct 2010 11:56

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.

Post Reply