# DbDataReader Streaming Serialization

> A C# serialization layer that streams DbDataReader results directly to JSON or XML through typed getters, avoiding DataTable/DTO materialization and resolving stable schema metadata once.

- Author: Muhammet Ali Köker
- Language: en
- Canonical: https://alikoker.com.tr/en/db-reader-streaming-serialization-csharp
- Translation: https://alikoker.com.tr/db-reader-streaming-serialization-csharp
- Published: 2020-07-03T15:27:00+03:00
- Modified: 2026-08-27T10:36:29+03:00
- Verified: 2026-08-27T10:36:29+03:00
- Type: project

The optimisation target here is the data path around serialization, not merely the serializer call itself. Materializing a large result set into a `DataTable`, a `List<DTO>` or dictionaries creates an intermediate object graph that then has to be walked again. This implementation connects `DbDataReader` directly to `Utf8JsonWriter` or `XmlWriter`.

Column names, type decisions and other stable schema information are prepared before the repeated row path. JSON names can be pre-encoded and common CLR types use typed getters. `DbRowView` deliberately reuses one view object as the reader advances instead of allocating a wrapper per row; consumers therefore must not retain it as if it were an immutable snapshot.

Very large LOB values are a separate problem. The scalar path is not advertised as a replacement for provider-level `GetStream` or `GetTextReader` access. A related design principle appears in [CSV Enumerable](/en/csv-enumerable-csharp), where header/property mapping is also performed once before streaming rows.

Design article: [Streaming JSON and XML Serialization from DbDataReader](/en/streaming-json-xml-serialization-from-dbdatareader)  
Repository: [GitHub](https://github.com/alikoker/db-reader-streaming-serialization-csharp)  
Zenodo release: [Zenodo](https://zenodo.org/records/22117281)  
DOI: [DOI](https://doi.org/10.5281/zenodo.22117281)

## Cite This Work

Köker, M. A. (2020). DbDataReader Streaming Serialization. alikoker.com.tr. https://alikoker.com.tr/en/db-reader-streaming-serialization-csharp

- BibTeX: https://alikoker.com.tr/en/db-reader-streaming-serialization-csharp.bib
- RIS: https://alikoker.com.tr/en/db-reader-streaming-serialization-csharp.ris
- CSL-JSON: https://alikoker.com.tr/en/db-reader-streaming-serialization-csharp.csl.json
