Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
即使成功,我如何强制回滚 SaveChanges() 方法?
您需要将其包装到事务范围中,然后在不完成范围的情况下将其处理掉。
using (var scope = new TransactionScope( TransactionScopeOption.Required, System.TimeSpan.MaxValue )) { /* your code goes here */ }
如果您想实际保存更改调用scope.Complete()
scope.Complete()
有关详细信息,请参阅此MSDN 帖子。