为什么System.Transactions的TransactionScope的默认的IsolationLevel Serializable接口 [英] Why is System.Transactions TransactionScope default Isolationlevel Serializable
问题描述
我只是想知道什么创造了System.Transactions的的TransactionScope :当一个好理由来使用序列化作为默认的IsolationLevel可能是,因为我想不出任何(它似乎是无法更改通过web / app.config中的默认,所以你总是要设置在你的code)
I am just wondering what a good reason to use Serializable as the default Isolationlevel may be when creating a the System.Transactions TransactionScope, because I cannot think of any (and it seems that you cannot change the default via web/app.config so you always have to set it in your code)
using(var transaction = TransactionScope()) {
... // creates a Transaction with Serializable Level
}
相反,我总是写样板code是这样的:
Instead i always have to write boilerplate code like this:
var txOptions = new System.Transactions.TransactionOptions();
txOptions.IsolationLevel = System.Transactions.IsolationLevel.ReadCommitted;
using(var transaction = new TransactionScope(TransactionScopeOption.Required,txOptions)) {
... //
}
任何想法?
推荐答案
事实上序列化
是默认来自时候,.NET甚至没有一年(前公布1999年),由DTC(分布式事务处理协调)节目。
The fact Serializable
is the default comes from times when .NET wasn't even released (before year 1999), from DTC (Distributed Transaction Coordinator) programming.
DTC使用本机的IsolationLevel 枚举:
DTC uses a native ISOLATIONLEVEL enumeration:
ISOLATIONLEVEL_SERIALIZABLE
由当前事务读取的数据不能
由另一个事务被改变,直至当前事务
饰面。没有新的数据可被插入这将影响当前
交易。 这是最安全的隔离级别,是默认的,
但允许并发的最低水平。
.NET 的TransactionScope
是建立在这些技术之上。
.NET TransactionScope
is built on top of these technologies.
现在,下一个问题是:为什么DTC定义 ISOLATIONLEVEL_SERIALIZABLE
作为默认事务级别?我想这是因为DTC是围绕1995年设计(1999年之前肯定)。在那个时候,SQL标准是SQL-92(或SQL2)。
Now, the next question is: why DTC defines ISOLATIONLEVEL_SERIALIZABLE
as the default transaction level? I suppose it's because DTC was designed around year 1995 (before 1999 for sure). At that time, the SQL Standard was SQL-92 (or SQL2).
和这里是 SQL-92 说,大约成交水平:
And here is what SQL-92 says about transaction levels:
这是SQL事务都有一个READ UNCOMMITTED隔离级别,
READ COMMITTED,可重复读取,或可序列化。隔离级别
一个SQL事务的定义在何种程度上的操作对系统蒸发散
在SQL事务SQL数据或模式是受
和效果可以影响到SQL的数据或模式在操作
并发SQL-交易。 SQL-事务隔离级别
默认情况下序列化。水平可通过显式地设置
An SQL-transaction has an isolation level that is READ UNCOMMITTED, READ COMMITTED, REPEATABLE READ, or SERIALIZABLE. The isolation level of an SQL-transaction defines the degree to which the opera- tions on SQL-data or schemas in that SQL-transaction are affected by the effects of and can affect operations on SQL-data or schemas in concurrent SQL-transactions. The isolation level of a SQL- transaction is SERIALIZABLE by default. The level can be explicitly set by the .
并发SQL-事务隔离级别执行
SERIALIZABLE是保证序列。可序列化exe-
意外地被定义为并发的操作的执行
rently执行SQL-交易产生相同的效果
这些相同的SQL事务的一些串行执行。串行exe-
意外地是中,每一个SQL事务执行完毕
先下一SQL事务就开始了。
The execution of concurrent SQL-transactions at isolation level SERIALIZABLE is guaranteed to be serializable. A serializable exe- cution is defined to be an execution of the operations of concur- rently executing SQL-transactions that produces the same effect as some serial execution of those same SQL-transactions. A serial exe- cution is one in which each SQL-transaction executes to completion before the next SQL-transaction begins.
这篇关于为什么System.Transactions的TransactionScope的默认的IsolationLevel Serializable接口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!