IRelationalStorage.ExecuteAsync 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
執行指定的 語句。 特別是用於 INSERT、 UPDATE、 DELETE 或 DDL 查詢。
public System.Threading.Tasks.Task<int> ExecuteAsync (string query, Action<System.Data.IDbCommand> parameterProvider, System.Threading.CancellationToken cancellationToken = default, System.Data.CommandBehavior commandBehavior = System.Data.CommandBehavior.Default);
abstract member ExecuteAsync : string * Action<System.Data.IDbCommand> * System.Threading.CancellationToken * System.Data.CommandBehavior -> System.Threading.Tasks.Task<int>
Public Function ExecuteAsync (query As String, parameterProvider As Action(Of IDbCommand), Optional cancellationToken As CancellationToken = Nothing, Optional commandBehavior As CommandBehavior = System.Data.CommandBehavior.Default) As Task(Of Integer)
參數
- query
- String
要執行的查詢。
- parameterProvider
- Action<IDbCommand>
將參數新增至查詢。 參數名稱必須符合查詢中定義的名稱。
- cancellationToken
- CancellationToken
取消語彙基元。 預設值為 None。
- commandBehavior
- CommandBehavior
應該使用的命令列為。 預設值為 Default。
傳回
受影響的資料列計數。
範例
此範例示範如何進行手動調整的資料庫呼叫。
//In contract to reading, execute queries are simpler as they return only
//the affected rows count if it is available.
var query = ""IF NOT EXISTS(SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = N'Test') CREATE TABLE Test(Id INT PRIMARY KEY IDENTITY(1, 1) NOT NULL);"
int affectedRowsCount = await storage.ExecuteAsync(query, command =>
{
//There aren't parameters here, but they'd be added like when reading.
//As the affected rows count is the only thing returned, there isn't
//facilities to read anything.
}).ConfigureAwait(continueOnCapturedContext: false);