when i try to attach entity to context i get an exception
An object with the same key already
exists in the ObjectStateManager. The
ObjectStateManager cannot track
multiple objects with the same key
This is expected behaviour.
But i would like to know how ObjectStateManager knows that?
I would like to do this check by myself before
If you are using DbContext API (you mentioned ef-code-first) you can simply use:
or more complex
In case of ObjectContext API you can use: