简体   繁体   English

使用实体框架还原数据库中的更改

[英]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. 我将SQL Server用作后端数据库,并使用Entity Framework 6对其进行访问。

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. 该方法对4个不同的数据库进行了多次调用,因此对4个不同的上下文进行了调用。 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. 我知道context.ChangeTracker.Entries()保留了数据库更改的记录。 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. 访问所有4个数据库后,我需要在方法末尾还原更改。

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 使用实体框架将更改保存回数据库 - Save changes back to database using entity framework 使用Entity Framework提交对数据库的更改 - Committing changes to the database using Entity Framework 实体框架不将更改保存到数据库中 - Entity Framework not Saving Changes into Database 使用Entity Framework保存1条记录的更改正在更新数据库中的2条记录 - Saving changes from 1 record using Entity Framework is updating 2 records in database DataGridView 是可编辑的,但不会使用实体框架将更改发送回数据库 - DataGridView is editable but does not send changes back to database using Entity Framework 使用实体框架更改持续交付和数据库架构 - Continuous delivery and database schema changes with entity framework 实体框架5日志数据库在运行时更改 - Entity Framework 5 log database changes at runtime 实体框架更新模型以反映数据库中的更改 - Entity Framework to update the Model to reflect the changes in database 模型更改后更新数据库 - 实体框架7 - Update Database after Model Changes - Entity Framework 7 将datagrid视图更改保存到数据库实体框架 - save datagrid view changes to database entity framework
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM