Could you give me an example of how to attach an object in Deleted state – I keep getting an exception [migrated]
- by carewithl
From MSDN :
An object in the Deleted state can only be attached when the
ObjectStateManager is already tracking the relationship instance.
Could you give me an example of how to attach an object in the Deleted state. I tried the following and got "System.InvalidOperationException: The object being attached is in an added or deleted state. Relationships cannot be created for objects in this state".
var contact = context.Contacts.First();
Console.WriteLine(contact.Addresses.Count()); // 2
var address = contact.Addresses.First();
context.Addresses.DeleteObject(address);
contact.Addresses.Attach(address); // InvalidOperationException
thank you