Madhur Maurya
Madhur Maurya

Reputation: 1070

Revert the changes in database using Entity Framework

I am using SQL Server as my back end database and Entity Framework 6 to access it.

I want to undo all the changes done to the database by a method. The method makes several calls to 4 different databases and thus 4 different contexts. I am not able to keep track of changes to revert them at the end.

I am aware of context.ChangeTracker.Entries() that keeps record of DB changes. But I am unable to utilize it because changes are lost as soon as a context goes out of scope. And I need need to revert the changes at the end of methods after accessing all 4 databases.

Upvotes: 0

Views: 1021

Answers (1)

Ravid Goldenberg
Ravid Goldenberg

Reputation: 2299

You should use transactionScope or beginTransaction, here you can get some basic information on both topics to get you started and here you can learn about the difference between them which will help you choose the right one for you.

Upvotes: 1

Related Questions