Table of Contents

Struct MappedCommand<T>

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

A deferred, type-locked query over a raw IDbCommand. Terminals are methods here.

public readonly record struct MappedCommand<T> : IMappedQuery<T>, IEquatable<MappedCommand<T>>

Type Parameters

T

The type each row is mapped to.

Implements
Inherited Members
Extension Methods

Remarks

The command belongs to the caller and is never disposed. Each terminal executes it again. The connection is opened only if it is closed, and a connection the terminal opened is closed (Close(), not Dispose()) when it ends; one that was already open is left open. The asynchronous terminals open and execute asynchronously when the command is a DbCommand, then read the rows with Read(), as an expressive command does by default.

A terminal returns the rows of the first result set only, then reads through the later sets without reading their rows, so a failure in a later statement is thrown as the provider raised it; command.SingleResult().Map<T>() turns that off, and so does SingleResult() after Map. See MappedQuery<T> for what a read-through does and does not do.

Methods

AsyncReads()

Reads the rows of an async terminal with ReadAsync instead of Read.

FirstAsync(CancellationToken)

Asynchronously reads the first mapped row; throws if the query returns no rows.

FirstOrDefaultAsync(CancellationToken)

Asynchronously reads the first mapped row.

SingleAsync(CancellationToken)

Asynchronously reads the only mapped row; throws if the query returns no rows or more than one.

SingleOrDefaultAsync(CancellationToken)

Asynchronously reads the only mapped row.

SingleResult()

Stops after the first result set and does not read through the later ones.

Skip(int)

Skips the first count mapped rows.

Stream(TimeSpan, CancellationToken)

Reads the rows one at a time off the open reader, lazily, as you pull them: on your own thread, with nothing read ahead.

StreamBuffered(TimeSpan, int, CancellationToken)

Reads the rows lazily through a bounded channel that buffers up to bufferSize rows; a size of 0 reads as Stream does, with no channel.

StreamBuffered(TimeSpan, CancellationToken)

Reads the rows lazily through a bounded channel that buffers up to 1,024 rows ahead of your loop, stopping the read when you stop pulling once the buffer is full.

Take(int)

Limits the result to at most count mapped rows.

ToArrayAsync(CancellationToken)

Asynchronously reads every mapped row into a new array.

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

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

ToDictionaryAsync<TKey>(Func<T, TKey>, CancellationToken)

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

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

Asynchronously reads every mapped row into a new Dictionary<TKey, TValue>, keyed by keySelector, with the value valueSelector returns for the row.

ToDictionaryAsync<TKey, TValue>(Func<T, TKey>, Func<T, TValue>, CancellationToken)

Asynchronously reads every mapped row into a new Dictionary<TKey, TValue>, keyed by keySelector, with the value valueSelector returns for the row.

ToHashSetAsync(IEqualityComparer<T>?, CancellationToken)

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

ToHashSetAsync(CancellationToken)

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

ToImmutableArrayAsync(CancellationToken)

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

ToListAsync(CancellationToken)

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

ToPooledBuffer(CancellationToken)

Reads every row into pooled arrays and keeps them until the returned buffer is disposed.

ToPooledBufferStream(CancellationToken)

Reads the query in a rolling stream of pooled arrays, once, for one consumer: it buffers the result in pooled arrays (from an array pool), not a channel of rows.

ToPooledStream(CancellationToken)

Reads the query in a rolling stream of pooled arrays, once, and yields the elements one by one: it buffers the result in pooled arrays (from an array pool), not a channel of rows.

UsePool(ArrayPool<T>, bool)

Chooses the pool this query's pooled arrays are rented from, and whether their rows are cleared when they go back.

See Also