Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Undelete an entity marked as EntityState.Delete?

instead of talking let me talk with code:

Dim Contact = Context.Contacts.Include("Phones")
Dim phone = Contact.Phones(0)
Contact.Remove(phone)

How do I refresh the context now, canceling last relation deletion?

I tried:

Context.Refresh(RefreshMode.StoreWins, phone) 'Doesn't recover the relation
Context.Refresh(RefreshMode.StoreWins, _
    ObjectStateManager.GetObjectStateEntries(EntityState.Deleted))

the last one throws an InvalidOperationException: The element at index 0 in the collection of objects to refresh has a null EntityKey property value or is not attached to this ObjectStateManager.

Important Table structure:

Contact: FirstName, LastName
Phone: Number, Note
ContactPhone (many-to-many): ContactId (nav), PhoneId (nav)

like image 988
Shimmy Weitzhandler Avatar asked Nov 18 '09 17:11

Shimmy Weitzhandler


Video Answer


1 Answers

Since I believe this is a bug, I reported it to Microsoft please vote and share your ideas: http://connect.microsoft.com/VisualStudio/feedback/ViewFeedback.aspx?FeedbackID=513174

like image 182
Shimmy Weitzhandler Avatar answered Sep 23 '22 08:09

Shimmy Weitzhandler