Search code examples
c#-4.0entity-framework-4ef4-code-onlydevart

Have a problem with EF 4.0 and ObjectStateManager (i think)


I have a serious problem, i have an unique key on field in db, I use Oracle(Devart Provider).

First time i preform an Insert -> (_objectSet.Add(entity)) via my repository it's ok,

BTW: I use Code Only model and CTP5.

Then if i want to insert it again it's fires an error that i have a "unique key constraint" and it's also alright.

After that no matter what do i do it's always throws me the same error!

What is that and how to fix it?

Thank you in advance.


Solution

  • The answer is simpler then i thought, i just have to Dettach the entity from Context, After i receive an exception of duplicate entities or any exception on it's holds in the context, the right way is to Dettach the entity and that's it.

    I've got this answer from Andrey in Devart.