DbContext.SaveChanges () without automatic transaction processing

Is there a way to execute DbContext.SaveChanges () without calling its internal automatic transaction processing?

I process the transaction (DbTransaction) myself, but when I call Commit, I get the error "SqlConnection does not support parallel transactions" I believe that this is due to the fact that SaveChanges does its internal transactional work, which I want to suppress.

.NET 4.5, EntityFramework.dll ver 5.

googling shows several approaches, but the code is incompatible. Some, showing SaveChanges, may take a boolean value that is not in this ver. and then calls the AcceptAllChanges () method, which also does not exist. Although some use System.Transaction.TransactionScope, they differ from each other in this System.Data.Common.DbTransaction.

+4
source share
1 answer

after many PITA efforts digging over EF. the only way I found that you have the right control over transactions is to use ObjectContext instead of DbContext.

http://sqlanywhere-forum.sap.com/questions/11320/entity-framework-savechanges-closes-connection

it hinted at an objectcontext

DbContext codebase genereated if your EDMX code generation strategy is set to None.

reference: Is ObjectContext deprecated in .NET 4.5?

changing it to the default value will give you the base code of the ObjectContext code.

what they have so far found out using DbContext, whenever you call it SaveChanges (), AUTO closes the bottom connection, and your next db task will have a new connection, which basically aborts the transaction to control what I'm looking for. you need to run entire db tasks without closing or re-creating conx inside the transaction.

using ObjectContext, SaveChanges () will not automatically close the connection if I set the transaction and connection codes correctly.

+1
source

Source: https://habr.com/ru/post/1492028/


All Articles