Edytuj

Udostępnij za pośrednictwem


RelationalStorageExtensions.ReadAsync Method

Definition

Overloads

ReadAsync<TResult>(IRelationalStorage, String, CancellationToken)

Uses IRelationalStorage with DbExtensions.ReflectionParameterProvider.

ReadAsync<TResult>(IRelationalStorage, String, Func<IDataRecord,TResult>, Action<IDbCommand>)

A simplified version of ReadAsync<TResult>(String, Action<IDbCommand>, Func<IDataRecord,Int32,CancellationToken,Task<TResult>>, CancellationToken, CommandBehavior)

ReadAsync<TResult>(IRelationalStorage, String, Object, CancellationToken)

Uses IRelationalStorage with ReflectionParameterProvider<T>(IDbCommand, T, IReadOnlyDictionary<String,String>).

ReadAsync<TResult>(IRelationalStorage, String, CancellationToken)

public static System.Threading.Tasks.Task<System.Collections.Generic.IEnumerable<TResult>> ReadAsync<TResult> (this Orleans.SqlUtils.IRelationalStorage storage, string query, System.Threading.CancellationToken cancellationToken = default);
static member ReadAsync : Orleans.SqlUtils.IRelationalStorage * string * System.Threading.CancellationToken -> System.Threading.Tasks.Task<seq<'Result>>
<Extension()>
Public Function ReadAsync(Of TResult) (storage As IRelationalStorage, query As String, Optional cancellationToken As CancellationToken = Nothing) As Task(Of IEnumerable(Of TResult))

Type Parameters

TResult

The type of the result.

Parameters

storage
IRelationalStorage

The storage to use.

query
String

Executes a given statement. Especially intended to use with SELECT statement, but works with other queries too.

cancellationToken
CancellationToken

The cancellation token. Defaults to None.

Returns

Task<IEnumerable<TResult>>

A list of objects as a result of the .

Applies to

ReadAsync<TResult>(IRelationalStorage, String, Func<IDataRecord,TResult>, Action<IDbCommand>)

public static System.Threading.Tasks.Task<System.Collections.Generic.IEnumerable<TResult>> ReadAsync<TResult> (this Orleans.SqlUtils.IRelationalStorage storage, string query, Func<System.Data.IDataRecord,TResult> selector, Action<System.Data.IDbCommand> parameterProvider);
static member ReadAsync : Orleans.SqlUtils.IRelationalStorage * string * Func<System.Data.IDataRecord, 'Result> * Action<System.Data.IDbCommand> -> System.Threading.Tasks.Task<seq<'Result>>
<Extension()>
Public Function ReadAsync(Of TResult) (storage As IRelationalStorage, query As String, selector As Func(Of IDataRecord, TResult), parameterProvider As Action(Of IDbCommand)) As Task(Of IEnumerable(Of TResult))

Type Parameters

TResult

Parameters

query
String
selector
Func<IDataRecord,TResult>
parameterProvider
Action<IDbCommand>

Returns

Task<IEnumerable<TResult>>

Applies to

ReadAsync<TResult>(IRelationalStorage, String, Object, CancellationToken)

public static System.Threading.Tasks.Task<System.Collections.Generic.IEnumerable<TResult>> ReadAsync<TResult> (this Orleans.SqlUtils.IRelationalStorage storage, string query, object parameters, System.Threading.CancellationToken cancellationToken = default);
static member ReadAsync : Orleans.SqlUtils.IRelationalStorage * string * obj * System.Threading.CancellationToken -> System.Threading.Tasks.Task<seq<'Result>>
<Extension()>
Public Function ReadAsync(Of TResult) (storage As IRelationalStorage, query As String, parameters As Object, Optional cancellationToken As CancellationToken = Nothing) As Task(Of IEnumerable(Of TResult))

Type Parameters

TResult

The type of the result.

Parameters

storage
IRelationalStorage

The storage to use.

query
String

Executes a given statement. Especially intended to use with SELECT statement, but works with other queries too.

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

Task<IEnumerable<TResult>>

A list of objects as a result of the .

Examples

This uses reflection to read results and match the parameters.

//This struct holds the return value in this example.        
public struct Information
{
    public string TABLE_CATALOG { get; set; }
    public string TABLE_NAME { get; set; }
}

//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 = "SELECT * FROM INFORMATION_SCHEMA.TABLES WHERE TABLE_NAME = @tname;";
IEnumerable<Information> informationData = await db.ReadAsync<Information>(query, new { tname = 200000 });

Applies to