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

前端 未结 4 1128
夕颜
夕颜 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:32

    In EF 6.1.2, a flag controls the behavior. Setting EnsureTransactionsForFunctionsAndCommands to false will affect SPs that have been imported into an entity (these call ExecuteFunction() internally).

     using (SomeEf6Context ctx = NewContext())
     {
         ctx.Configuration.EnsureTransactionsForFunctionsAndCommands = false;
         // Call an imported SP
     }      
    

    The setting will not affect any SaveChanges() calls.

    MSDN Link

提交回复
热议问题