DataContext.Transaction 属性
定义
获取或设置用于访问数据库的 .NET Framework 的本地事务。Gets or sets a local transaction for the .NET Framework to use to access the database.
public:
property System::Data::Common::DbTransaction ^ Transaction { System::Data::Common::DbTransaction ^ get(); void set(System::Data::Common::DbTransaction ^ value); };
public System.Data.Common.DbTransaction Transaction { get; set; }
member this.Transaction : System.Data.Common.DbTransaction with get, set
Public Property Transaction As DbTransaction
属性值
执行查询和命令时由 DataContext 使用的事务对象。The transaction object used by the DataContext when executing queries and commands.
注解
此属性的主要方案是与关系 ADO.NET 代码的互操作性。The primary scenario for this property is interoperability with relational ADO.NET code. 例如,当您编写自己的 Create / Update / Delete 方法以在 Transaction ADO 对象上设置属性 Command 时,请使用此属性。For example, use this property when you write your own Create/Update/Delete methods to set the Transaction property on the ADO Command object.
注意以下事项:Note the following:
如果未显式设置此属性,则 getter 将返回 null。If this property has not been explicitly set, the getter returns null.
如果代码在上下文中执行 Transaction ,则设置此属性将引发异常。If the code is executing in a Transaction context, setting this property throws an exception.
如果设置了此属性并打开了新的 Transaction ,则执行查询或更新时将引发异常。If this property is set and a new Transaction is opened, an exception is thrown when a query or update is executed.