Class MappedDbQuery<T>
- Namespace
- Open.Database.Extensions
- Assembly
- Open.Database.Extensions.Core.dll
A DbQuery that is already mapped: the command text, the kind, the timeout, the
map that turns a row into a T, and the options that never change from one
call to the next. It has no connection yet and cannot be read until it has one.
public sealed class MappedDbQuery<T>
Type Parameters
TThe type each row is mapped to.
- Inheritance
-
MappedDbQuery<T>
- Inherited Members
Remarks
It is immutable, so a static field holds it:
static readonly MappedDbQuery<Post> ByAuthor = DbQuery.Procedure("ByAuthor").Map<Post>();.
From here the order is the caller's.
ByAuthor.Using(source).AddParam("authorId", id).ToListAsync(ct) is the first way to write it;
ByAuthor.AddParam("authorId", id).Using(source).ToListAsync(ct) gives the same command.
Using(DbConnection) returns the ordinary MappedQuery<T> view, with the
options of this definition applied, so every terminal, Skip and Take are the ones the view has.
Set on the definition, for every query made from it: the map, SingleResult(), AsyncReads(),
UsePool(ArrayPool<T>, bool) and (on the DbQuery before Map)
SetTimeout(ushort). A query made from it can still apply SingleResult, AsyncReads and
UsePool for one call. Chosen per call: the parameters, Skip and Take.
Methods
- AddParam(string, string?)
Adds a named parameter before the source is known.
- AddParam<TValue>(string, TValue)
Adds a named parameter before the source is known.
- AddParam<TValue>(TValue, string?)
Adds a parameter whose name is derived from the argument's expression, before the source is known.
- AddParams<TValues>(TValues)
Adds the members of an object as parameters, before the source is known.
- AsyncReads()
Reads the rows with the asynchronous read of the provider, in every query made from this definition (see AsyncReads()).
- Params<TParams>()
Declares the type of the values: a struct (a readonly record struct is the intended shape) whose public properties and fields are the parameters.
- SingleResult()
Reads only the first result set, in every query made from this definition (see SingleResult()).
- UsePool(ArrayPool<T>, bool)
Takes the arrays that hold the rows from
pool, in every query made from this definition (see UsePool(ArrayPool<T>, bool)).
- Using(DbConnection)
Reads the query on a connection the caller owns.
- Using(DbTransaction)
Reads the query inside a transaction the caller owns.
- Using<TConnection>(IDbConnectionFactory<TConnection>)
Reads the query on a connection made by a factory.
- Using<TConnection>(IDbConnectionPool<TConnection>)
Reads the query on a connection taken from a pool.