Back to directory
I wrote three articles about this.ArticleThe series are all centered around a topic, that is, when. NET will upgrade transactionscope to a distributed transaction. Today I borrowed the threadstatic feature to prove this knowledge point. The following is a summary:
Transactionscope article:
26th timesChange uncertainty to confirmation ~ When Will transactionscope be upgraded to a distributed transaction?
27th timesChange uncertainty to confirmation ~ When is transactionscope upgraded to a distributed transaction ~ Continued
28th timesChange uncertainty to confirmation ~ When is transactionscope upgraded to a distributed transaction ~ Continue (avoid unnecessary MSDTC)
Threadstatic feature article:
The foundation is the top priority ~ Threadstatic static field uniqueness in each thread
Summary:
As long as the data context is one, no distributed transactions will be generated
As long as the data context is one, multiple submitchanges will be merged and submitted at a time.
First, this is a datacontext graph with the threadstatic feature. I have disabled the MSDTC Service.
The following figure shows how to use a normal data context of an instance. It generates multiple data contexts and promotes transactionscope to a distributed transaction. Therefore, the exceptions shown in the following figure are thrown, haha!
The following is a method call: common instance Context
Threadstatic data context
The following is the transaction'sProgramIt has multiple operations, and each operation has its own submitchanges ()
The SQL statement it generates uses an SQL connection pool, and the performance is already optimal!
Back to directory