Linq to sql add/update in different methods with different datacontexts
- by Kurresmack
I have to methods, Add() and Update() which both create a datacontext and returns the object created/updated.
In my unit test I call first Add(), do some stuff and then call Update(). The problem is that Update() fails with the exception:
System.Data.Linq.DuplicateKeyException: Cannot add an entity with a key that is already in use..
I understand the issue but want to know what to do about it? I've read a bit about how to handle multiple datacontext objects and from what I've heard this way is OK.
I understand that the entity is still attached to the datacontext in Add() but I need to find out how to solve this?
Thanks in advance