Search code examples
c#wcfodata

Undelete Entity in WCF


I have a WCF-client consuming a OData service. At some point the user can delete an entity. I do this with the DataServiceContext.DeleteObject(object entity) method. So the Entity.State becomes Deleted.

The user has the possibility to undo the deletion. How can I make the state back to Modified?


Solution

  • I finally achieved to do it by:

    DataServiceContext.Detach(obj);
    DataServiceContext.AttachTo("EntitySetName", obj);
    

    This removed the deleted status from the object and added it as modified.