DataContext.Transaction 屬性

定義

取得或設定 .NET Framework.NET Framework 用來存取資料庫的本機交易。Gets or sets a local transaction for the .NET Framework.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.NETADO.NET程式碼的互通性。The primary scenario for this property is interoperability with relational ADO.NETADO.NET code. 例如, Create當您撰寫自己Update / / 的方法Transaction來設定ADOCommand物件上的屬性時,請使用這個屬性。 DeleteFor 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開啟新的,則在執行查詢或更新時,就會擲回例外狀況(exception)。If this property is set and a new Transaction is opened, an exception is thrown when a query or update is executed.

適用於