Compartilhar via


IRelationalStorage.ExecuteAsync Método

Definição

Executa uma determinada instrução. Especialmente destinado a usar com consultas INSERT, UPDATE, DELETE ou 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)

Parâmetros

query
String

A consulta a ser executada.

parameterProvider
Action<IDbCommand>

Adiciona parâmetros à consulta. Os nomes de parâmetro devem corresponder aos definidos na consulta.

cancellationToken
CancellationToken

O token de cancelamento. Assume o padrão de None.

commandBehavior
CommandBehavior

O comportamento de comando que deve ser usado. Assume o padrão de Default.

Retornos

Contagem de linhas afetadas.

Exemplos

Este exemplo mostra como fazer uma chamada de banco de dados ajustada à mão.

//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);                

Aplica-se a