views:

25

answers:

1

Hello guys! I was confused with my problem. I'm using Entity Framework and want to save entities on hard disk and then to restore them. I have no problem with Serializing/Deserializing but i get an exception "The object cannot be added to the ObjectStateManager because it already has an EntityKey. Use ObjectContext.Attach to attach an object that has an existing key" when i try to add deserialized object to my datacontext. And nothing happens when i just Attach my entity to datacontext

How to achieve my goal? Thx in advance! -Alexandr-

A: 

You need to attach then add.

Ben Robinson
I've tried it but it doesn't work.An exception 'An object with the same key already exists in the ObjectStateManager. The existing object is in the Unchanged state. An object can only be added to the ObjectStateManager again if it is in the added state' occured. I have no idea how to achieve save/restore functions now...
Alexandr