EF6 wraps every single stored procedure call in its own transaction. How to prevent this?

前端 未结 4 1133
夕颜
夕颜 2020-12-08 14:16

Profiled with SQL Server Profiler: EF 6 wraps every single stored procedure call with BEGIN TRAN and COMMIT TRAN.

Is not it a breaking cha

4条回答
  •  不知归路
    2020-12-08 14:50

    As what crokusek said, you can set that flag to disable transactions for SPs.

    If you are using any Dependency Injection (DI) library, you can set that like this(I am using Simple Injector):

    public partial class Startup
    {
        public Container ConfigureSimpleInjector(IAppBuilder app)
        {
            var container = new Container();
    
            // Configure OWIN and Identity Framework
            ...
    
            // Configure persistence
            container.RegisterPerWebRequest(() =>
            {
                var fakeDbContext = new FakeDbContext();
                fakeDbContext.Configuration.EnsureTransactionsForFunctionsAndCommands = false;
                return fakeDbContext;
            }
    
            // Register other services
            ...
    
            container.Verify();
    
            // For MVC
            DependencyResolver.SetResolver(new SimpleInjectorDependencyResolver(container));
    
            return container;
         }
    }
    

提交回复
热议问题