Method Map
- Namespace
- Open.Database.Extensions
- Assembly
- Open.Database.Extensions.Core.dll
Map<T>(IExecuteReader, RowMap<T>?)
Locks in a mapping to model type T and returns a
deferred MappedQuery<T>.
Nothing runs until a terminal, such as
ToListAsync(CancellationToken), is invoked.
public static MappedQuery<T> Map<T>(this IExecuteReader command, RowMap<T>? map)
Parameters
commandIExecuteReaderThe command to read from.
mapRowMap<T>The prebuilt RowMap<T> to read with; null reads as
Map<T>()does.
Returns
- MappedQuery<T>
A deferred query whose results are mapped to
T.
Type Parameters
TThe model type to map the values to.
Remarks
The mapping is compiled once per result-set shape and cached.
A type with a public parameterless constructor is built with
new T(), and its public settable properties
(init and required ones too)
are set from the columns.
Any other type is built through its one public constructor
(a positional record, a record struct, a class with one constructor),
and the properties the constructor does not cover are set afterwards.
A required property needs a column.
A single value such as int
(a primitive, an enum, string, decimal,
a date or time, Guid, byte[]
or a Nullable<T> of one)
is read from the first column of each row,
converted as a property of that type is;
a NULL into a non-nullable value type throws ValueMappingException naming the type and the row,
so declare int? when a NULL is expected.
A T that cannot be mapped
(an interface, an abstract class,
a type with two or more public constructors and none without parameters)
throws InvalidOperationException when the map is built or
Default is read,
which the overloads without a RowMap<T> do at the call.
See Records and constructors.
Pass a RowMap<T> to read columns whose names differ from the
properties; the overload without a map reads by column name.
Columns match a property exactly, else ignoring case, else ignoring case
and underscores (author_id feeds AuthorId).
Declare the RowMap<T> once and pass it: a map built in the
call (a new RowMap<T>(...) or a collection expression in the
argument) is rebuilt, and its row reader compiled, on every call; see
Columns named differently.
A terminal returns the rows of the first result set only
(a result here is one whole result set, what
NextResult() moves between; never a row)
and never maps a later set.
It then reads through the later sets without reading their rows, so a
failure in a later statement is thrown as the provider raised it.
That is not done with SingleResult(), written before Map
(command.SingleResult().Map<T>(), see
SingleResult(IExecuteReader)) or after it
(command.Map<T>().SingleResult(), the same),
when the caller stops reading early,
or when the mapping, a selector or the caller's handler throws.
A later failure can follow a write that already committed, so a caller
that retries can repeat it, and the rows read are lost when it throws.
Exceptions
- ArgumentNullException
commandis null.
- See Also
-
RowMap<T>
Map<T>(IExecuteReader)
Locks in a mapping to model type T and returns a
deferred MappedQuery<T>.
Nothing runs until a terminal, such as
ToListAsync(CancellationToken), is invoked.
public static MappedQuery<T> Map<T>(this IExecuteReader command)
Parameters
commandIExecuteReaderThe command to read from.
Returns
- MappedQuery<T>
A deferred query whose results are mapped to
T.
Type Parameters
TThe model type to map the values to.
Remarks
The mapping is compiled once per result-set shape and cached.
A type with a public parameterless constructor is built with
new T(), and its public settable properties
(init and required ones too)
are set from the columns.
Any other type is built through its one public constructor
(a positional record, a record struct, a class with one constructor),
and the properties the constructor does not cover are set afterwards.
A required property needs a column.
A single value such as int
(a primitive, an enum, string, decimal,
a date or time, Guid, byte[]
or a Nullable<T> of one)
is read from the first column of each row,
converted as a property of that type is;
a NULL into a non-nullable value type throws ValueMappingException naming the type and the row,
so declare int? when a NULL is expected.
A T that cannot be mapped
(an interface, an abstract class,
a type with two or more public constructors and none without parameters)
throws InvalidOperationException when the map is built or
Default is read,
which the overloads without a RowMap<T> do at the call.
See Records and constructors.
Pass a RowMap<T> to read columns whose names differ from the
properties; the overload without a map reads by column name.
Columns match a property exactly, else ignoring case, else ignoring case
and underscores (author_id feeds AuthorId).
Declare the RowMap<T> once and pass it: a map built in the
call (a new RowMap<T>(...) or a collection expression in the
argument) is rebuilt, and its row reader compiled, on every call; see
Columns named differently.
A terminal returns the rows of the first result set only
(a result here is one whole result set, what
NextResult() moves between; never a row)
and never maps a later set.
It then reads through the later sets without reading their rows, so a
failure in a later statement is thrown as the provider raised it.
That is not done with SingleResult(), written before Map
(command.SingleResult().Map<T>(), see
SingleResult(IExecuteReader)) or after it
(command.Map<T>().SingleResult(), the same),
when the caller stops reading early,
or when the mapping, a selector or the caller's handler throws.
A later failure can follow a write that already committed, so a caller
that retries can repeat it, and the rows read are lost when it throws.
Exceptions
- ArgumentNullException
commandis null.
- See Also
-
RowMap<T>
Map<T>(IExecuteReader, Func<IDataRecord, T>)
Locks in a custom projection and returns a deferred
MappedQuery<T>.
Nothing runs until a terminal is invoked;
selector is applied per row as the reader streams.
public static MappedQuery<T> Map<T>(this IExecuteReader command, Func<IDataRecord, T> selector)
Parameters
commandIExecuteReaderThe command to read from.
selectorFunc<IDataRecord, T>The transform applied to each IDataRecord.
Returns
- MappedQuery<T>
A deferred query whose results are produced by
selector.
Type Parameters
TThe type each record is projected to.
Exceptions
- ArgumentNullException
commandorselectoris null.
Map<T>(IDataReader, RowMap<T>?)
Locks in a mapping to model type T over a data
reader the caller owns and returns a deferred
MappedReader<T>.
Nothing runs until a terminal, such as
ToListAsync(CancellationToken), is invoked.
public static MappedReader<T> Map<T>(this IDataReader reader, RowMap<T>? map)
Parameters
readerIDataReaderThe reader to read from, positioned on the result set to map.
mapRowMap<T>The prebuilt RowMap<T> to read with; null reads as
Map<T>()does.
Returns
- MappedReader<T>
A deferred query whose results are mapped to
T.
Type Parameters
TThe model type to map the values to.
Remarks
The reader belongs to the caller: it is never opened, closed or disposed, and NextResult() is never called on it. Rows are read from the current position of the current result set, and the rows read stay read.
How T is mapped is the same as for
Map<T>(IExecuteReader, RowMap<T>?):
a RowMap<T> reads columns whose names differ from the
properties, and the overload without one reads by column name
(exactly, else ignoring case, else ignoring case and underscores, so
author_id feeds AuthorId).
A single value such as int is read from the first column.
Exceptions
- ArgumentNullException
readeris null.
- See Also
-
RowMap<T>
Map<T>(IDataReader)
Locks in a mapping to model type T over a data
reader the caller owns and returns a deferred
MappedReader<T>.
Nothing runs until a terminal, such as
ToListAsync(CancellationToken), is invoked.
public static MappedReader<T> Map<T>(this IDataReader reader)
Parameters
readerIDataReaderThe reader to read from, positioned on the result set to map.
Returns
- MappedReader<T>
A deferred query whose results are mapped to
T.
Type Parameters
TThe model type to map the values to.
Remarks
The reader belongs to the caller: it is never opened, closed or disposed, and NextResult() is never called on it. Rows are read from the current position of the current result set, and the rows read stay read.
How T is mapped is the same as for
Map<T>(IExecuteReader, RowMap<T>?):
a RowMap<T> reads columns whose names differ from the
properties, and the overload without one reads by column name
(exactly, else ignoring case, else ignoring case and underscores, so
author_id feeds AuthorId).
A single value such as int is read from the first column.
Exceptions
- ArgumentNullException
readeris null.
- See Also
-
RowMap<T>
Map<T>(IDataReader, Func<IDataRecord, T>)
Locks in a custom projection over a data reader the caller owns and
returns a deferred MappedReader<T>.
Nothing runs until a terminal is invoked;
selector is applied per row as the reader streams.
public static MappedReader<T> Map<T>(this IDataReader reader, Func<IDataRecord, T> selector)
Parameters
readerIDataReaderThe reader to read from, positioned on the result set to map.
selectorFunc<IDataRecord, T>The transform applied to each IDataRecord.
Returns
- MappedReader<T>
A deferred query whose results are produced by
selector.
Type Parameters
TThe type each record is projected to.
Remarks
The reader belongs to the caller: it is never opened, closed or disposed, and NextResult() is never called on it. Rows are read from the current position of the current result set, and the rows read stay read.
Exceptions
- ArgumentNullException
readerorselectoris null.
Map<T>(IDbCommand, RowMap<T>?)
Locks in a mapping to model type T over a command
and returns a deferred MappedCommand<T>.
Nothing runs until a terminal, such as
ToListAsync(CancellationToken), is invoked.
public static MappedCommand<T> Map<T>(this IDbCommand command, RowMap<T>? map)
Parameters
commandIDbCommandThe command to execute.
mapRowMap<T>The prebuilt RowMap<T> to read with; null reads as
Map<T>()does.
Returns
- MappedCommand<T>
A deferred query whose results are mapped to
T.
Type Parameters
TThe model type to map the values to.
Remarks
The command belongs to the caller and is never disposed.
The connection is opened only if it is closed, and a connection this call
opened is closed (not disposed) when it ends; one that was already open
is left open.
Like an expressive command, a terminal reads through the later result
sets after the first, so a failure in a later statement is thrown;
command.SingleResult().Map<T>() turns that off
(SingleResult() after Map does too).
How T is mapped is the same as for
Map<T>(IExecuteReader, RowMap<T>?):
a RowMap<T> reads columns whose names differ from the
properties, and the overload without one reads by column name
(exactly, else ignoring case, else ignoring case and underscores, so
author_id feeds AuthorId).
A single value such as int is read from the first column.
Exceptions
- ArgumentNullException
commandis null.
- See Also
-
RowMap<T>
Map<T>(IDbCommand)
Locks in a mapping to model type T over a command
and returns a deferred MappedCommand<T>.
Nothing runs until a terminal, such as
ToListAsync(CancellationToken), is invoked.
public static MappedCommand<T> Map<T>(this IDbCommand command)
Parameters
commandIDbCommandThe command to execute.
Returns
- MappedCommand<T>
A deferred query whose results are mapped to
T.
Type Parameters
TThe model type to map the values to.
Remarks
The command belongs to the caller and is never disposed.
The connection is opened only if it is closed, and a connection this call
opened is closed (not disposed) when it ends; one that was already open
is left open.
Like an expressive command, a terminal reads through the later result
sets after the first, so a failure in a later statement is thrown;
command.SingleResult().Map<T>() turns that off
(SingleResult() after Map does too).
How T is mapped is the same as for
Map<T>(IExecuteReader, RowMap<T>?):
a RowMap<T> reads columns whose names differ from the
properties, and the overload without one reads by column name
(exactly, else ignoring case, else ignoring case and underscores, so
author_id feeds AuthorId).
A single value such as int is read from the first column.
Exceptions
- ArgumentNullException
commandis null.
- See Also
-
RowMap<T>
Map<T>(IDbCommand, Func<IDataRecord, T>)
Locks in a custom projection over a command and returns a deferred
MappedCommand<T>.
Nothing runs until a terminal is invoked;
selector is applied per row as the reader streams.
public static MappedCommand<T> Map<T>(this IDbCommand command, Func<IDataRecord, T> selector)
Parameters
commandIDbCommandThe command to execute.
selectorFunc<IDataRecord, T>The transform applied to each IDataRecord.
Returns
- MappedCommand<T>
A deferred query whose results are produced by
selector.
Type Parameters
TThe type each record is projected to.
Remarks
The command belongs to the caller and is never disposed.
The connection is opened only if it is closed, and a connection this call
opened is closed (not disposed) when it ends; one that was already open
is left open.
Like an expressive command, a terminal reads through the later result
sets after the first, so a failure in a later statement is thrown;
command.SingleResult().Map<T>() turns that off
(SingleResult() after Map does too).
Exceptions
- ArgumentNullException
commandorselectoris null.
Map<T>(DataTable, RowMap<T>?)
Locks in a mapping to model type T over the rows of
a DataTable you already have and returns a deferred
MappedTable<T>.
Nothing runs until a terminal, such as
ToListAsync(CancellationToken), is invoked.
public static MappedTable<T> Map<T>(this DataTable table, RowMap<T>? map)
Parameters
tableDataTableThe table whose rows are mapped.
mapRowMap<T>The prebuilt RowMap<T> to read with; null reads as
Map<T>()does.
Returns
- MappedTable<T>
A deferred query whose results are mapped to
T.
Type Parameters
TThe model type to map the values to.
Remarks
A shortcut for table.CreateDataReader().Map<T>(), with the
difference that the view owns and disposes the readers it creates.
Each terminal reads the table's current rows through a new
DataTableReader and disposes it.
The table is not changed or cleared, so the view can be read more than
once.
How T is mapped is the same as for
Map<T>(IExecuteReader, RowMap<T>?):
a RowMap<T> reads columns whose names differ from the
properties, and the overload without one reads by column name
(exactly, else ignoring case, else ignoring case and underscores, so
author_id feeds AuthorId).
A single value such as int is read from the first column.
Exceptions
- ArgumentNullException
tableis null.
- See Also
-
RowMap<T>
Map<T>(DataTable)
Locks in a mapping to model type T over the rows of
a DataTable you already have and returns a deferred
MappedTable<T>.
Nothing runs until a terminal, such as
ToListAsync(CancellationToken), is invoked.
public static MappedTable<T> Map<T>(this DataTable table)
Parameters
tableDataTableThe table whose rows are mapped.
Returns
- MappedTable<T>
A deferred query whose results are mapped to
T.
Type Parameters
TThe model type to map the values to.
Remarks
A shortcut for table.CreateDataReader().Map<T>(), with the
difference that the view owns and disposes the readers it creates.
Each terminal reads the table's current rows through a new
DataTableReader and disposes it.
The table is not changed or cleared, so the view can be read more than
once.
How T is mapped is the same as for
Map<T>(IExecuteReader, RowMap<T>?):
a RowMap<T> reads columns whose names differ from the
properties, and the overload without one reads by column name
(exactly, else ignoring case, else ignoring case and underscores, so
author_id feeds AuthorId).
A single value such as int is read from the first column.
Exceptions
- ArgumentNullException
tableis null.
- See Also
-
RowMap<T>
Map<T>(DataTable, Func<IDataRecord, T>)
Locks in a custom projection over the rows of a DataTable
you already have and returns a deferred MappedTable<T>.
Nothing runs until a terminal is invoked;
selector is applied per row as the table is read.
public static MappedTable<T> Map<T>(this DataTable table, Func<IDataRecord, T> selector)
Parameters
tableDataTableThe table whose rows are projected.
selectorFunc<IDataRecord, T>The transform applied to each IDataRecord.
Returns
- MappedTable<T>
A deferred query whose results are produced by
selector.
Type Parameters
TThe type each record is projected to.
Remarks
Each terminal reads the table's current rows through a new DataTableReader and disposes it. The table is not changed or cleared, so the view can be read more than once.
Exceptions
- ArgumentNullException
tableorselectoris null.