Table of Contents

Class MappedQueryExtensions

Namespace
Open.Database.Extensions
Assembly
Open.Database.Extensions.Core.dll

Terminal operations for IMappedQuery<T>: they materialize the mapped rows into a collection or take a single row. MappedQuery<T> and its skip and take variants expose the same operations directly.

[SuppressMessage("Design", "CA1068:CancellationToken parameters must come last", Justification = "Convenience and style.")]
public static class MappedQueryExtensions
Inheritance
MappedQueryExtensions
Inherited Members

Examples

List<Customer> all = connection
    .Command("SELECT Id, Name FROM Customers")
    .Map<Customer>()
    .ToList();

Customer? first = await connection
    .Command("SELECT Id, Name FROM Customers ORDER BY Id")
    .Map<Customer>()
    .FirstOrDefaultAsync(cancellationToken);

Remarks

Every terminal executes the command, reads the rows while the connection is open, and releases the connection before the call returns (or, for the asynchronous forms, before the returned task completes). The asynchronous forms accept a CancellationToken; when it cannot be canceled, the cancellation token set on the underlying command applies.

Exceptions from the provider (for example DbException) propagate unchanged and the connection is still released.

Methods

FirstOrDefaultAsync<T>(IMappedQuery<T>, CancellationToken)

Asynchronously reads the first mapped row.

FirstOrDefault<T>(IMappedQuery<T>)

Reads the first mapped row.

ReadAsync<T>(IMappedQuery<T>, Func<IAsyncEnumerable<T>, ValueTask>, CancellationToken)

Asynchronously executes the query and passes the mapped rows to handler as they are read. Use this overload when the handler does not need the cancellation token.

ReadAsync<T>(IMappedQuery<T>, CancellationToken, Func<IAsyncEnumerable<T>, CancellationToken, ValueTask>)

Asynchronously executes the query and passes the mapped rows to handler together with the cancellation token in effect. The cancellation token comes first so the handler can be written as a trailing lambda.

ReadAsync<T>(IMappedQuery<T>, CancellationToken, Func<IAsyncEnumerable<T>, ValueTask>)

Asynchronously executes the query and passes the mapped rows to handler. The cancellation token comes first so the handler can be written as a trailing lambda.

ReadAsync<T, TResult>(IMappedQuery<T>, Func<IAsyncEnumerable<T>, ValueTask<TResult>>, CancellationToken)

Asynchronously executes the query, passes the mapped rows to handler as they are read, and returns the handler's result. Use this overload when the handler does not need the cancellation token.

ReadAsync<T, TResult>(IMappedQuery<T>, CancellationToken, Func<IAsyncEnumerable<T>, CancellationToken, ValueTask<TResult>>)

Asynchronously executes the query, passes the mapped rows to handler together with the cancellation token in effect, and returns the handler's result. The cancellation token comes first so the handler can be written as a trailing lambda.

ReadAsync<T, TResult>(IMappedQuery<T>, CancellationToken, Func<IAsyncEnumerable<T>, ValueTask<TResult>>)

Asynchronously executes the query, passes the mapped rows to handler, and returns the handler's result. The cancellation token comes first so the handler can be written as a trailing lambda.

SingleOrDefaultAsync<T>(IMappedQuery<T>, CancellationToken)

Asynchronously reads the only mapped row.

SingleOrDefault<T>(IMappedQuery<T>)

Reads the only mapped row.

ToArrayAsync<T>(IMappedQuery<T>, CancellationToken)

Asynchronously reads every mapped row into a new array.

ToArray<T>(IMappedQuery<T>)

Reads every mapped row into a new array.

ToDictionaryAsync<T, TKey>(IMappedQuery<T>, Func<T, TKey>, IEqualityComparer<TKey>?, CancellationToken)

Asynchronously reads every mapped row into a new Dictionary<TKey, TValue>, keyed by keySelector.

ToDictionary<T, TKey>(IMappedQuery<T>, Func<T, TKey>, IEqualityComparer<TKey>?)

Reads every mapped row into a new Dictionary<TKey, TValue>, keyed by keySelector.

ToHashSetAsync<T>(IMappedQuery<T>, IEqualityComparer<T>?, CancellationToken)

Asynchronously reads every mapped row into a new HashSet<T>.

ToHashSet<T>(IMappedQuery<T>, IEqualityComparer<T>?)

Reads every mapped row into a new HashSet<T>.

ToImmutableArrayAsync<T>(IMappedQuery<T>, CancellationToken)

Asynchronously reads every mapped row into a new ImmutableArray<T>.

ToImmutableArray<T>(IMappedQuery<T>)

Reads every mapped row into a new ImmutableArray<T>.

ToListAsync<T>(IMappedQuery<T>, CancellationToken)

Asynchronously reads every mapped row into a new List<T>.

ToList<T>(IMappedQuery<T>)

Reads every mapped row into a new List<T>.

See Also