Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions Source/Generator/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ Core's hidden entry `GeneratedRowMap.Create<T>(Bind)` (for this generator only;

- **Binding.** Core's read loop calls `Bind` once per result set, after the first row is read and before it is mapped (not for a result set with no row to map). Except for a trusted model (below), `Bind` matches the reader's column count and names against a small
cache of layouts (or resolves a new one) and returns that layout's row reader, or `null` for a layout it does not serve: the runtime map then serves
that result set exactly as the default map would. A next result set is bound again, at its own ordinals. `Bind` is thread-safe.
that result set exactly as the default map would. A next result set is bound again, at its own ordinals. `Bind` is thread-safe. The match costs
about a nanosecond per column, once per result set; a trusted model skips it.
- **Each member is read by its own type**, as a hand-written reader reads it: a typed getter (`GetInt32`, `GetString` and so on), an enum its
underlying type's getter, `byte[]`, `object`, interfaces and `dynamic` a cast of `GetValue`, and any other type (`DateOnly`, `TimeSpan`, `uint`
and so on) `GetFieldValue<T>`. The column's type is not looked at: the provider converts or throws.
Expand All @@ -25,7 +26,9 @@ Core's hidden entry `GeneratedRowMap.Create<T>(Bind)` (for this generator only;
initializer and reaches a setter with its own code.
- **Errors.** Core's loop reports a failed row as it does for the runtime map: a `ValueMappingException` naming the model type and the 0-based row
(skipped rows counted, restarting per result set), the exception inside. A `DbException` or a cancellation passes through. Nothing is read from the
reader after a failure; no member or column is named.
reader after a failure; no member or column is named. The loop catches around its call of the row reader alone, so a failure of the read itself,
of adding the row or of a cancel passes through unchanged. A row reader that cannot load (a model assembly changed since the consumer was built)
is reported as a failed row, with the load error inside.

## Known differences from the runtime map

Expand Down
3 changes: 3 additions & 0 deletions docsite/articles/mapping.md
Original file line number Diff line number Diff line change
Expand Up @@ -226,6 +226,9 @@ Unless the model declares every column's ordinal, a generated reader matches the
- **No conversions.** Only what the provider's getter converts is converted: elsewhere the read fails (`ValueMappingException`). What a provider does with a column of another kind (convert, coerce or throw), and the value it then gives, is the provider's: on SQL Server, for one, an `int` member over a `bigint` column fails. The [generator's README](https://github.com/Open-NET-Libraries/Open.Database.Extensions/blob/master/Source/Generator/README.md#known-differences-from-the-runtime-map) lists the conversions the runtime map makes that a generated reader does not. Make the member the column's type, store an enum or a `Guid` as text only for a `string` member, or switch the generator off.
- A model whose mapped members **all** declare `[Column(Order = n)]` is trusted. Its reader takes those positions and looks at nothing else in the result: no declared name or column count is checked.
- A NULL in a non-nullable member is reported with the provider's or the cast's own exception inside the `ValueMappingException`, where the runtime map may report `SqlNullValueException`.

The name match is the one thing a generated reader does that a hand-written reader, which assumes its columns' positions, does not. It costs about a nanosecond per column, once per result set, not per row. A model whose members all declare `[Column(Order = n)]` skips it, and its reader then does only what a hand-written reader does.

To switch the generator off for a project (the setting applies to the project it is in: a library built with the generator keeps its generated readers):

```xml
Expand Down