How can I reject all changes in a Linq to SQL's DataContext?

后端 未结 10 981
礼貌的吻别
礼貌的吻别 2020-11-27 18:57

On Linq to SQL\'s DataContext I am able to call SubmitChanges() to submit all changes.

What I want is to somehow reject all changes in the datacontext and rollback a

10条回答
  •  失恋的感觉
    2020-11-27 19:19

    Calling Clear() on the Updates, Deletes and Inserts collection does not work.

    GetOriginalEntityState() can be useful, but it only gives the IDs for foreign key relationships, not the actual entities so you're left with a detached object.

    Here's an article that explains how to discard changes from the data context: http://graemehill.ca/discard-changes-in-linq-to-sql-datacontext

    EDIT: Calling Refresh() will undo updates, but not deletes and inserts.

提交回复
热议问题