简体   繁体   中英

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.

您应该使用transactionScopebeginTransaction在这里您可以获取有关这两个主题的一些基本信息以开始使用, 在这里您可以了解它们之间的区别,这将帮助您选择合适的主题。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM