Transaction and DBContext failed

Hi, I am using the first approach of Entity Framework 4.1. I have a class MyContainerthat inherits DBContext.

I have a process that has 7 steps at each step, accesses many repository methods (about 60). This process is performed automatically or depends on the business logic and user requirements. Now for the performance point of view for the automatic process, I created a context, i.e. The object MyContaineronce, and passed it to all methods and disposed of it at the end of the process, and its work stopped and improved performance. But when this process is executed in the same order, the methods are executed, and the container is created and placed in the method itself. for example below, but this is just rough code.

public bool UpdateProcess(Process process, MyContainer container = null)
    {
        bool disposeContainer = false;
        if (container == null)
        {
            container = new MyContainer();
            disposeContainer = true;
        }
        var result = SaveProcess(container, process);
        container.SaveChanges();
        if (disposeContainer)
            container.Dispose();
        return result;
    }

, bll , u.Now , , - ui. Exception "Transaction (Process ID 65). " UpdateProcess() , , .SaveChanges().

.

,

public bool UpdateProcess(Process process, MyContainer container = null)
 {         bool disposeContainer = false;        
           if (container == null)  
           {             
                  container = new MyContainer();         
                  disposeContainer = true;         
            }
       using(var trans=new TransactionScop(TransactionScopeOption.RequiresNew))        
       { 
          var result = SaveProcess(container, process);
          container.SaveChanges();
          trans.Complete();
       }        
          if (disposeContainer)           
          container.Dispose();        
          return result;   
 } 

. , bll.

.

+3
1

(sql deadlocking), , - .

, , , . . microsoft

, . .

, , , :

  • ,
  • , .
  • / .
  • , , .
  • , , , , , / ..
+2

All Articles