共用方式為


IDbTransactionInterceptor.TransactionStartingAsync 方法

定義

在 EF 想要呼叫 之前呼叫 BeginTransactionAsync(IsolationLevel, CancellationToken)

public System.Threading.Tasks.Task<Microsoft.EntityFrameworkCore.Diagnostics.InterceptionResult<System.Data.Common.DbTransaction>> TransactionStartingAsync (System.Data.Common.DbConnection connection, Microsoft.EntityFrameworkCore.Diagnostics.TransactionStartingEventData eventData, Microsoft.EntityFrameworkCore.Diagnostics.InterceptionResult<System.Data.Common.DbTransaction> result, System.Threading.CancellationToken cancellationToken = default);
public System.Threading.Tasks.ValueTask<Microsoft.EntityFrameworkCore.Diagnostics.InterceptionResult<System.Data.Common.DbTransaction>> TransactionStartingAsync (System.Data.Common.DbConnection connection, Microsoft.EntityFrameworkCore.Diagnostics.TransactionStartingEventData eventData, Microsoft.EntityFrameworkCore.Diagnostics.InterceptionResult<System.Data.Common.DbTransaction> result, System.Threading.CancellationToken cancellationToken = default);
public virtual System.Threading.Tasks.ValueTask<Microsoft.EntityFrameworkCore.Diagnostics.InterceptionResult<System.Data.Common.DbTransaction>> TransactionStartingAsync (System.Data.Common.DbConnection connection, Microsoft.EntityFrameworkCore.Diagnostics.TransactionStartingEventData eventData, Microsoft.EntityFrameworkCore.Diagnostics.InterceptionResult<System.Data.Common.DbTransaction> result, System.Threading.CancellationToken cancellationToken = default);
abstract member TransactionStartingAsync : System.Data.Common.DbConnection * Microsoft.EntityFrameworkCore.Diagnostics.TransactionStartingEventData * Microsoft.EntityFrameworkCore.Diagnostics.InterceptionResult<System.Data.Common.DbTransaction> * System.Threading.CancellationToken -> System.Threading.Tasks.Task<Microsoft.EntityFrameworkCore.Diagnostics.InterceptionResult<System.Data.Common.DbTransaction>>
abstract member TransactionStartingAsync : System.Data.Common.DbConnection * Microsoft.EntityFrameworkCore.Diagnostics.TransactionStartingEventData * Microsoft.EntityFrameworkCore.Diagnostics.InterceptionResult<System.Data.Common.DbTransaction> * System.Threading.CancellationToken -> System.Threading.Tasks.ValueTask<Microsoft.EntityFrameworkCore.Diagnostics.InterceptionResult<System.Data.Common.DbTransaction>>
abstract member TransactionStartingAsync : System.Data.Common.DbConnection * Microsoft.EntityFrameworkCore.Diagnostics.TransactionStartingEventData * Microsoft.EntityFrameworkCore.Diagnostics.InterceptionResult<System.Data.Common.DbTransaction> * System.Threading.CancellationToken -> System.Threading.Tasks.ValueTask<Microsoft.EntityFrameworkCore.Diagnostics.InterceptionResult<System.Data.Common.DbTransaction>>
override this.TransactionStartingAsync : System.Data.Common.DbConnection * Microsoft.EntityFrameworkCore.Diagnostics.TransactionStartingEventData * Microsoft.EntityFrameworkCore.Diagnostics.InterceptionResult<System.Data.Common.DbTransaction> * System.Threading.CancellationToken -> System.Threading.Tasks.ValueTask<Microsoft.EntityFrameworkCore.Diagnostics.InterceptionResult<System.Data.Common.DbTransaction>>
Public Function TransactionStartingAsync (connection As DbConnection, eventData As TransactionStartingEventData, result As InterceptionResult(Of DbTransaction), Optional cancellationToken As CancellationToken = Nothing) As Task(Of InterceptionResult(Of DbTransaction))
Public Function TransactionStartingAsync (connection As DbConnection, eventData As TransactionStartingEventData, result As InterceptionResult(Of DbTransaction), Optional cancellationToken As CancellationToken = Nothing) As ValueTask(Of InterceptionResult(Of DbTransaction))
Public Overridable Function TransactionStartingAsync (connection As DbConnection, eventData As TransactionStartingEventData, result As InterceptionResult(Of DbTransaction), Optional cancellationToken As CancellationToken = Nothing) As ValueTask(Of InterceptionResult(Of DbTransaction))

參數

connection
DbConnection

連接。

eventData
TransactionStartingEventData

連線和交易的相關內容資訊。

result
InterceptionResult<DbTransaction>

如果存在,則表示目前的結果。 如果某些先前的攔截器藉由呼叫 SuppressWithResult(TResult) 來隱藏執行,這個值將會 HasResult 設定 true 為 。 這個值通常用來作為這個方法實作的傳回值。

cancellationToken
CancellationToken

等候 CancellationToken 工作完成時要觀察的 。

傳回

如果 HasResult 為 false,EF 會如常繼續。 如果 HasResult 為 true,EF 將會隱藏即將執行的作業,並改用 Result 。 任何未嘗試變更結果攔截器的這個方法實作是傳回 result 傳入的值,通常使用 FromResult<TResult>(TResult)

例外狀況

適用於