Edytuj

Udostępnij za pośrednictwem


RelationalStorageExtensions.ExecuteAsync Method

Definition

Overloads

ExecuteAsync(IRelationalStorage, String, CancellationToken)

Uses IRelationalStorage with ReflectionSelector<TResult>(IDataRecord).

ExecuteAsync(IRelationalStorage, String, Object, CancellationToken)

Uses IRelationalStorage with ReflectionSelector<TResult>(IDataRecord).

ExecuteAsync(IRelationalStorage, String, CancellationToken)

public static System.Threading.Tasks.Task<int> ExecuteAsync (this Orleans.SqlUtils.IRelationalStorage storage, string query, System.Threading.CancellationToken cancellationToken = default);
static member ExecuteAsync : Orleans.SqlUtils.IRelationalStorage * string * System.Threading.CancellationToken -> System.Threading.Tasks.Task<int>
<Extension()>
Public Function ExecuteAsync (storage As IRelationalStorage, query As String, Optional cancellationToken As CancellationToken = Nothing) As Task(Of Integer)

Parameters

storage
IRelationalStorage

The storage to use.

query
String

Executes a given statement. Especially intended to use with INSERT, UPDATE, DELETE or DDL queries.

cancellationToken
CancellationToken

The cancellation token. Defaults to None.

Returns

Affected rows count.

Applies to

ExecuteAsync(IRelationalStorage, String, Object, CancellationToken)

public static System.Threading.Tasks.Task<int> ExecuteAsync (this Orleans.SqlUtils.IRelationalStorage storage, string query, object parameters, System.Threading.CancellationToken cancellationToken = default);
static member ExecuteAsync : Orleans.SqlUtils.IRelationalStorage * string * obj * System.Threading.CancellationToken -> System.Threading.Tasks.Task<int>
<Extension()>
Public Function ExecuteAsync (storage As IRelationalStorage, query As String, parameters As Object, Optional cancellationToken As CancellationToken = Nothing) As Task(Of Integer)

Parameters

storage
IRelationalStorage

The storage to use.

query
String

Executes a given statement. Especially intended to use with INSERT, UPDATE, DELETE or DDL queries.

parameters
Object

Adds parameters to the query. Parameter names must match those defined in the query.

cancellationToken
CancellationToken

The cancellation token. Defaults to None.

Returns

Affected rows count.

Examples

This uses reflection to provide parameters to an execute query that reads only affected rows count if available.

//Here reflection (<seealso cref="M:Orleans.SqlUtils.DbExtensions.ReflectionParameterProvider``1(System.Data.IDbCommand,``0,System.Collections.Generic.IReadOnlyDictionary{System.String,System.String})"></seealso>)
is used to match parameter names as well as to read back the results (<seealso cref="M:Orleans.SqlUtils.DbExtensions.ReflectionSelector``1(System.Data.IDataRecord)"></seealso>).
var query = "IF NOT EXISTS(SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = @tname) CREATE TABLE Test(Id INT PRIMARY KEY IDENTITY(1, 1) NOT NULL);"
await db.ExecuteAsync(query, new { tname = "test_table" });

Applies to