TransactionIsolationLevel 列舉

定義

指定 TransactionAttribute 的值。

C#
[System.Serializable]
public enum TransactionIsolationLevel
繼承
TransactionIsolationLevel
屬性

欄位

名稱 Description
Any 0

元件的隔離等級 (Isolation Level) 是從呼叫元件的隔離等級來取得。 如果這是根元件,則使用的隔離等級為 Serializable

ReadCommitted 2

正在讀取資料時使用共用鎖定,以避免讀到已修改的資料,但資料可能會在交易結束前變更,導致非可重複的讀取或虛設資料。

ReadUncommitted 1

共用鎖定已核發,並且沒有獨佔鎖定被認可。

RepeatableRead 3

鎖定是加諸於查詢中使用的所有資料,以防止其他使用者更新資料。 防止非可重複的讀取,但虛設資料列仍有可能發生。

Serializable 4

防止更新或插入,直到交易完成為止。

範例

下列程式代碼範例示範型別的使用 TransactionIsolationLevel

C#
using System;
using System.EnterpriseServices;
using System.Reflection;

// References:
// System.EnterpriseServices

// An instance of this class will inherit its caller's transaction isolation
// level if available. If not, it will use isolation level Serializable.
[Transaction(Isolation=TransactionIsolationLevel.Any)]
public class TransactionAttribute_IsolationAny : ServicedComponent
{
}

// An instance of this class will read only committed data, but non-repeatable
// reads and phantom rows are still possible.
[Transaction(Isolation=TransactionIsolationLevel.ReadCommitted)]
public class TransactionAttribute_IsolationReadCommitted : ServicedComponent
{
}

// An instance of this class will read committed and uncommitted data, so dirty
// reads, non-repeatable reads, and phantom rows are possible.
[Transaction(Isolation=TransactionIsolationLevel.ReadUncommitted)]
public class TransactionAttribute_IsolationReadUncommitted : ServicedComponent
{
}

// An instance of this class will read only committed data and place shared
// locks on the data, preventing other users from modifying it, but other users
// can still insert rows into the data set, so phantom rows are still possible.
[Transaction(Isolation=TransactionIsolationLevel.RepeatableRead)]
public class TransactionAttribute_IsolationRepeatableRead : ServicedComponent
{
}

// An instance of this class will read only committed data and place a range
// lock on the data set, preventing other users from updating or inserting rows
// into the data set until its transaction is complete.
[Transaction(Isolation=TransactionIsolationLevel.Serializable)]
public class TransactionAttribute_IsolationSerializable : ServicedComponent
{
}

適用於

產品 版本
.NET Framework 1.1, 2.0, 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1