EntityConnection.BeginTransaction 方法

定义

开始一项数据库事务。Begins a database transaction.

重载

BeginTransaction()

使用基础提供程序开始一个事务。Begins a transaction by using the underlying provider.

BeginTransaction(IsolationLevel)

使用基础提供程序开始一个具有指定隔离级别的事务。Begins a transaction with the specified isolation level by using the underlying provider.

BeginTransaction()

使用基础提供程序开始一个事务。Begins a transaction by using the underlying provider.

public:
 System::Data::EntityClient::EntityTransaction ^ BeginTransaction();
public System.Data.EntityClient.EntityTransaction BeginTransaction ();
override this.BeginTransaction : unit -> System.Data.EntityClient.EntityTransaction
Public Function BeginTransaction () As EntityTransaction

返回

EntityTransaction

一个新的 EntityTransactionA new EntityTransaction. 返回的 EntityTransaction 实例以后可以与 EntityCommand 关联以执行该事务下的命令。The returned EntityTransaction instance can later be associated with the EntityCommand to execute the command under that transaction.

例外

基础提供程序未知。The underlying provider is not known.

- 或 --or-

对已具有当前事务的 调用 。The call to BeginTransaction() was made on an EntityConnection that already has a current transaction.

- 或 --or-

EntityConnection 的状态不是 OpenThe state of the EntityConnection is not Open.

注解

BeginTransaction 方法使用 Unspecified 事务隔离级别。The BeginTransaction method uses the Unspecified transaction isolation level. 若要指定不同的隔离级别,请调用 BeginTransactionTo specify a different isolation level, call BeginTransaction. 不同的基础提供程序可能用不同的方法对此值进行解释。This value might be interpreted differently by different underlying providers. 如果要应用程序可以跨多个提供程序移植,该应用程序应通过调用 BeginTransaction 显式指定事务隔离级别。If you want your application to be portable across multiple providers, it should explicitly specify the transaction isolation level by calling BeginTransaction.

任何特定时刻都只能存在一个通过 BeginTransaction 创建的活动事务。At any particular moment there can be no more than one active transaction that was created through BeginTransaction. 尝试对已具有当前事务的 BeginTransaction 调用任何 EntityConnection 重载将引发 InvalidOperationExceptionAn attempt to call any of the BeginTransaction overloads on an EntityConnection that already has a current transaction results in an InvalidOperationException.

适用于

BeginTransaction(IsolationLevel)

使用基础提供程序开始一个具有指定隔离级别的事务。Begins a transaction with the specified isolation level by using the underlying provider.

public:
 System::Data::EntityClient::EntityTransaction ^ BeginTransaction(System::Data::IsolationLevel isolationLevel);
public System.Data.EntityClient.EntityTransaction BeginTransaction (System.Data.IsolationLevel isolationLevel);
override this.BeginTransaction : System.Data.IsolationLevel -> System.Data.EntityClient.EntityTransaction
Public Function BeginTransaction (isolationLevel As IsolationLevel) As EntityTransaction

参数

isolationLevel
IsolationLevel

事务的隔离级别。The isolation level of the transaction.

返回

EntityTransaction

一个新的 EntityTransactionA new EntityTransaction. 返回的 EntityTransaction 实例以后可以与 EntityCommand 关联以执行该事务下的命令。The returned EntityTransaction instance can later be associated with the EntityCommand to execute the command under that transaction.

例外

基础提供程序未知。The underlying provider is not known.

- 或 --or-

对已具有当前事务的 调用 。The call to BeginTransaction() was made on an EntityConnection that already has a current transaction.

- 或 --or-

EntityConnection 的状态不是 OpenThe state of the EntityConnection is not Open.

注解

任何特定时刻都只能存在一个通过 BeginTransaction 创建的活动事务。At any particular moment there can be no more than one active transaction that was created through BeginTransaction. 尝试对已具有当前事务的 BeginTransaction 调用任何 EntityConnection 重载将引发 InvalidOperationExceptionAn attempt to call any of the BeginTransaction overloads on an EntityConnection that already has a current transaction results in an InvalidOperationException.

适用于