none
Undo command in Entity Framewok ? RRS feed

  • Question

  • Hello !

    Is there any Undo command in entity framework ?

    If not, is there any way to create it ?

    Thank you !


    • Edited by dcode25 Sunday, March 22, 2015 5:40 AM
    Sunday, March 22, 2015 5:40 AM

Answers

  • Hello dcode25,

    >>Is there any Undo command in entity framework ?

    It is not very clear what operation you want to undo, if they are changes as insert/update/delete, since Entity Framework would use a state manager class to manage these states of entities, you could achieve the undo operation by changing these states of entities, you could do that with 4 level:

    Context Level

    Entity Set Level

    Entity Level

    Property Level

    For detail implementation, please check this code sample:

    How to undo the changes in Entity Framework 4.1 and later

    Regards,

    Fred.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Tuesday, March 24, 2015 1:48 AM
    Moderator
  • The changes are committed when you call the SaveChanges() method on the context. After you have done this there is no way to "undo" the changes.

    Before you call the SaveChanges() method you could just reload the entities from the context or call the SetValues method and explicitly change the State of all entity objects as described here: http://stackoverflow.com/questions/16437083/dbcontext-discard-changes-without-disposing

    Hope that helps.


    Please remember to close your threads by marking all helpful posts as answer then start a new thread if you have a new question.

    Tuesday, March 24, 2015 3:25 PM

All replies

  • Hello dcode25,

    >>Is there any Undo command in entity framework ?

    It is not very clear what operation you want to undo, if they are changes as insert/update/delete, since Entity Framework would use a state manager class to manage these states of entities, you could achieve the undo operation by changing these states of entities, you could do that with 4 level:

    Context Level

    Entity Set Level

    Entity Level

    Property Level

    For detail implementation, please check this code sample:

    How to undo the changes in Entity Framework 4.1 and later

    Regards,

    Fred.


    We are trying to better understand customer views on social support experience, so your participation in this interview project would be greatly appreciated if you have time. Thanks for helping make community forums a great place.
    Click HERE to participate the survey.

    Tuesday, March 24, 2015 1:48 AM
    Moderator
  • The changes are committed when you call the SaveChanges() method on the context. After you have done this there is no way to "undo" the changes.

    Before you call the SaveChanges() method you could just reload the entities from the context or call the SetValues method and explicitly change the State of all entity objects as described here: http://stackoverflow.com/questions/16437083/dbcontext-discard-changes-without-disposing

    Hope that helps.


    Please remember to close your threads by marking all helpful posts as answer then start a new thread if you have a new question.

    Tuesday, March 24, 2015 3:25 PM