- r - 以节省内存的方式增长 data.frame
- ruby-on-rails - ruby/ruby on rails 内存泄漏检测
- android - 无法解析导入android.support.v7.app
- UNIX 域套接字与共享内存(映射文件)
_context.SaveChanges
和 _context.AcceptAllChanges()
之间的区别是 AcceptAllChanges()
是一种从数据库或回滚(丢弃)用户在未使用 SaveChanges()
最佳答案
ObjectContext.AcceptAllChanges Method - MSDN
If the SaveChanges method was called and the AcceptAllChangesAfterSave was not specified, the user must call the AcceptAllChanges method. The AcceptAllChanges method is useful in the scenario where a transaction has failed and a user wants to retry.
您可能会看到:http://blogs.msdn.com/b/alexj/archive/2009/01/11/savechanges-false.aspx
If you call SaveChanges() or SaveChanges(true),the EF simply assumes that if its work completes okay, everything is okay, so it will discard the changes it has been tracking, and wait for new changes.
Unfortunately though if something goes wrong somewhere else in the transaction, because the EF discarded the changes it was tracking, we can’t recover.
This is where SaveChanges(false) and AcceptAllChanges() come in.
SaveChanges(false) tells the EF to execute the necessary database commands, but hold on to the changes, so they can be replayed if necessary.
Now if the broader transaction fails you can retry the EF specific bits, with another call to SaveChanges(false). Alternatively you can walk through the state-manager to log what failed.
Once the broader transaction succeeds, you simply call AcceptAllChanges() manually, and the changes that were being tracked are discarded.
关于c# - Entity Framework 中的 SaveChanges 与 AcceptAllChanges,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12859304/
以下有什么区别: db.AcceptAllChanges(); // vs db.SaveChanges(); db.AddToCust
我使用的是 .NET 3.5 SP1。我有一个删除一些实体的简单脚本。 var people = (from Person p in context.People wher
我一直在调查事务,只要我将 false 传递给 SaveChanges() 然后调用 AcceptAllChanges,它们似乎就会在 EF 中自行处理() 如果没有错误: SaveChanges(f
_context.SaveChanges 和 _context.AcceptAllChanges() 之间的区别是 AcceptAllChanges() 是一种从数据库或回滚(丢弃)用户在未使用 Sa
我很困惑,我徒劳地尝试对多个插入进行排队,我有数千个添加要做,所以我只想真正执行一次数据库。 我正在使用 .net 4 和 Entity Framework 4,并且还添加了对 system.data
我是一名优秀的程序员,十分优秀!