Class BaseTypeParser<T>
Base class for a custom result shape. Implement Parse(DbDataReader) and Default() then use the inherited query methods to run commands with that shape.
public abstract class BaseTypeParser<T> : ITypeParser<T>, ITypeParser, IDisposable
Type Parameters
T
- Inheritance
-
BaseTypeParser<T>
- Implements
-
ITypeParser<T>
- Derived
- Inherited Members
- Extension Methods
Properties
Behavior
The reader behavior this parser wants, passed to ExecuteReader(CommandBehavior).
public abstract CommandBehavior Behavior { get; }
Property Value
Remarks
Often SequentialAccess or SingleResult.
Methods
CanParse(ColumnInfo[])
Whether this parser can read a result carrying schema.
public abstract bool CanParse(ColumnInfo[] schema)
Parameters
schemaColumnInfo[]
Returns
Remarks
A parser may accept several schemas. A parser that reads names and types at each call may accept every schema.
Default()
The value to return when the result has no row, an empty collection or optional, for instance.
public abstract T Default()
Returns
- T
Dispose()
Performs application-defined tasks associated with freeing, releasing, or resetting unmanaged resources.
public virtual void Dispose()
Parse(DbDataReader)
Parses one T starting at the current row, advancing the reader as it goes.
CanContinue reports the state of the reader on return, true when it is
positioned on an untreated row, false when no row is left
public abstract (bool CanContinue, T Result) Parse(DbDataReader reader)
Parameters
readerDbDataReader
Returns
- (bool CanContinue, T Result)
ParseAsync(DbDataReader, CancellationToken)
Parses one T starting at the current row, advancing the reader as it goes.
CanContinue reports the state of the reader on return, true when it is
positioned on an untreated row, false when no row is left
public abstract ValueTask<(bool CanContinue, T Result)> ParseAsync(DbDataReader reader, CancellationToken ct = default)
Parameters
readerDbDataReaderctCancellationToken
Returns
- ValueTask<(bool CanContinue, T Result)>
Query(DbCommand, ICache, bool)
Runs command and reads its result as T, also letting cache learn from the executed command.
public T Query(DbCommand command, ICache cache, bool disposeCommand = false)
Parameters
Returns
- T
Query(DbCommand, bool)
Runs command and reads its result as T, disposing the command afterward when disposeCommand is set.
public T Query(DbCommand command, bool disposeCommand = false)
Parameters
Returns
- T
Query(IDbCommand, ICache, bool)
Runs command and reads its result as T, also letting cache learn from the executed command.
public T Query(IDbCommand command, ICache cache, bool disposeCommand = false)
Parameters
commandIDbCommandcacheICachedisposeCommandbool
Returns
- T
Query(IDbCommand, bool)
Runs command and reads its result as T, disposing the command afterward when disposeCommand is set.
public T Query(IDbCommand command, bool disposeCommand = false)
Parameters
commandIDbCommanddisposeCommandbool
Returns
- T
QueryAsync(DbCommand, ICache, bool, CancellationToken)
Runs command and reads its result as T, also letting cache learn from the executed command.
public Task<T> QueryAsync(DbCommand command, ICache cache, bool disposeCommand = false, CancellationToken ct = default)
Parameters
commandDbCommandcacheICachedisposeCommandboolctCancellationToken
Returns
- Task<T>
QueryAsync(DbCommand, bool, CancellationToken)
Runs command and reads its result as T, disposing the command afterward when disposeCommand is set.
public Task<T> QueryAsync(DbCommand command, bool disposeCommand = false, CancellationToken ct = default)
Parameters
commandDbCommanddisposeCommandboolctCancellationToken
Returns
- Task<T>
QueryAsync(IDbCommand, ICache, bool, CancellationToken)
Runs command and reads its result as T, also letting cache learn from the executed command.
public Task<T> QueryAsync(IDbCommand command, ICache cache, bool disposeCommand = false, CancellationToken ct = default)
Parameters
commandIDbCommandcacheICachedisposeCommandboolctCancellationToken
Returns
- Task<T>
QueryAsync(IDbCommand, bool, CancellationToken)
Runs command and reads its result as T, disposing the command afterward when disposeCommand is set.
public Task<T> QueryAsync(IDbCommand command, bool disposeCommand = false, CancellationToken ct = default)
Parameters
commandIDbCommanddisposeCommandboolctCancellationToken
Returns
- Task<T>