Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/entity-framework/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# saveChanges()失败+EF时重新使用事务_C#_Entity Framework_Transactionscope_Savechanges - Fatal编程技术网

C# saveChanges()失败+EF时重新使用事务

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

在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 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,因此在事务中出现任意失败后,您无法重试

它可能适用于并发异常或其他特定故障,但您需要将其作为特殊情况进行测试和处理