C# saveChanges()失败+EF时重新使用事务
在context.savechanges失败的情况下,事务数据库状态和事务状态中应该是什么。我是否可以重用同一事务,但创建新的上下文C# saveChanges()失败+EF时重新使用事务,c#,entity-framework,transactionscope,savechanges,C#,Entity Framework,Transactionscope,Savechanges,在context.savechanges失败的情况下,事务数据库状态和事务状态中应该是什么。我是否可以重用同一事务,但创建新的上下文 // Should the retry be at this level in case saveChanges() fail. using(var transaction = new TransactionScope()) { // retry at this level in case saveChanges() fail. Use t
// Should the retry be at this level in case saveChanges() fail.
using(var transaction = new TransactionScope())
{
// retry at this level in case saveChanges() fail. Use the ambient transaction?
using(var context = new DbContext)
{
//do some update and encounter exception (e.g., concurrency exception.)
context.saveChanges();
}
transaction.Complete();
}
在context.savechanges失败的情况下,事务数据库状态和事务状态中应该是什么。我是否可以重用同一事务,但创建新的上下文
确切的行为是特定于提供程序和特定于错误的。但一般的答案是,失败可能会毁掉整个事务,甚至DbContext,因此在事务中出现任意失败后,您无法重试
它可能适用于并发异常或其他特定故障,但您需要将其作为特殊情况进行测试和处理