Method SingleResult
- Namespace
- Open.Database.Extensions
- Assembly
- Open.Database.Extensions.Core.dll
SingleResult(IExecuteReader)
Opts an expressive command out of the read-through, so that the query reads only the first result set.
public static IExecuteReader SingleResult(this IExecuteReader command)
Parameters
commandIExecuteReaderThe command to read from.
Returns
- IExecuteReader
The command, to be followed by
Map.
Remarks
A Map terminal returns the rows of the first result set
(a result here is one whole result set, what NextResult() moves between; never a row)
and then reads through the later sets without reading their rows,
so a failure in a later statement is thrown as the provider raised it.
This is the one explicit opt-out of that.
With it the reader is asked for SingleResult
(and SingleRow too for FirstOrDefault when nothing is skipped),
which lets the provider stop early.
It asserts nothing: it does not check that there is only one result set.
Call it before Map, as in command.SingleResult().Map<Post>().ToListAsync(cancellationToken).
command.SingleResult().Map<T>() is exactly
command.Map<T>().SingleResult(), which still works,
and the Map overloads that follow are the ones of
Map<T>(IExecuteReader, RowMap<T>?).
The command is not changed, so it can be used again without the opt-out.
A later failure can follow a write that already committed, so a caller that retries can repeat it, and the opt-out hides that failure.
The result is a view of the command for Map.
Used as an IExecuteReader directly,
it runs the command with SingleResult added to each call.
A reader (IDataReader) and a DataTable have nothing to opt out of:
their Map never reads through, so there is no SingleResult before it.
Exceptions
- ArgumentNullException
commandis null.
SingleResult(IDbCommand)
Opts a command out of the read-through, so that the query reads only the first result set.
public static IDbCommand SingleResult(this IDbCommand command)
Parameters
commandIDbCommandThe command to read from.
Returns
- IDbCommand
The command, to be followed by
Map.
Remarks
A Map terminal returns the rows of the first result set
(a result here is one whole result set, what NextResult() moves between; never a row)
and then reads through the later sets without reading their rows,
so a failure in a later statement is thrown as the provider raised it.
This is the one explicit opt-out of that.
It asserts nothing: it does not check that there is only one result set.
Call it before Map, as in command.SingleResult().Map<Post>().ToListAsync(cancellationToken).
command.SingleResult().Map<T>() is exactly
command.Map<T>().SingleResult(), which still works,
and the Map overloads that follow are the ones of
Map<T>(IDbCommand, RowMap<T>?).
The command is not changed and belongs to the caller; the query never disposes it.
A caller that uses the returned view directly as a command should know
that disposing the view disposes the command, so dispose one or the other.
A later failure can follow a write that already committed, so a caller that retries can repeat it, and the opt-out hides that failure.
The result is a view of the command for Map:
it is not a DbCommand, so pass the command itself to anything else.
Used as an IDbCommand directly,
it runs the command with SingleResult added to each reader it opens.
Exceptions
- ArgumentNullException
commandis null.