TransactionOption 枚举

定义

指定组件请求的自动事务类型。

C#
[System.Serializable]
public enum TransactionOption
继承
TransactionOption
属性

字段

名称 说明
Disabled 0

忽略当前上下文中的任何事务。

NotSupported 1

使用非受控事务在上下文中创建组件。

Required 3

如果事务存在,则共享该事务;如有必要,则创建新事务。

RequiresNew 4

使用新事务创建组件,而与当前上下文的状态无关。

Supported 2

如果事务存在,则共享该事务。

示例

下面的代码示例演示如何使用 TransactionOption 类型。

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

// References:
// System.EnterpriseServices

// An instance of this class will not participate in transactions, but can
// share its caller's context even if its caller is configured as
// NotSupported, Supported, Required, or RequiresNew.
[Transaction(TransactionOption.Disabled)]
public class TransactionAttribute_TransactionDisabled : ServicedComponent
{
}

// An instance of this class will not participate in transactions, and will
// share its caller's context only if its caller is also configured as
// NotSupported.
[Transaction(TransactionOption.NotSupported)]
public class TransactionAttribute_TransactionNotSupported : ServicedComponent
{
}

// An instance of this class will participate in its caller's transaction
// if one exists.
[Transaction(TransactionOption.Supported)]
public class TransactionAttribute_TransactionSupported : ServicedComponent
{
}

// An instance of this class will participate in its caller's transaction
// if one exists. If not, a new transaction will be created for it.
[Transaction(TransactionOption.Required)]
public class TransactionAttribute_TransactionRequired : ServicedComponent
{
}

// A new transaction will always be created for an instance of this class.
[Transaction(TransactionOption.RequiresNew)]
public class TransactionAttribute_TransactionRequiresNew : ServicedComponent
{
}

注解

使用 .NET 安装工具 (Regsvcs.exe) 时, 的 ServicedComponent 事务选项默认为 Disabled

适用于

产品 版本
.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