feat: StreamPaged<T> - stream a paged JSON envelope in a single round-trip (fixes #5009) - #5014
Merged
jeremydmiller merged 3 commits intoJul 22, 2026
Conversation
…-trip (fixes JasperFx#5009) Adds a new StreamPaged<T> result type to Marten.AspNetCore that streams a paged list of documents plus paging metadata as a single JSON envelope directly to the HTTP response, in a single database round trip: {"pageNumber":3,"pageSize":25,"totalItemCount":1207,"pageCount":49, "hasNextPage":true,"hasPreviousPage":true,"items":[...]} Implementation: - Marten.Linq.MartenLinqQueryable<T>.StreamPagedJsonArray: sets Statistics, applies Skip/Take, delegates to the provider. - MartenLinqQueryProvider.StreamPagedMany: builds the Linq statement/command (which includes count(*) OVER() as total_rows via LinqConstants.StatsColumn when Statistics is set), then executes via the session. - QuerySession.StreamPagedMany + JsonStreamingExtensions.StreamPagedMany: reads total_rows from the first row of the DbDataReader, computes pageCount/hasNextPage/hasPreviousPage (mirroring PagedList.ProcessResults), writes the envelope prefix, then streams each row's raw document JSON into the items array without deserializing/reserializing documents. - QueryableExtensions.StreamPagedJsonArray<T> (Marten core): public entry point exposing the above. - Marten.AspNetCore.QueryableExtensions.WritePaged<T> + StreamPaged<T> (IResult + IEndpointMetadataProvider, mirroring StreamMany<T>): the minimal-API/Wolverine.Http-facing wrapper. Zero-row result sets produce totalItemCount: 0, pageCount: 0, and an empty items array (count(*) OVER() is not present when no rows match). Tests: - src/DocumentDbTests/Reading/Json/streaming_json_results.cs: 8 new Facts covering first/middle/last/single page, no-hits, and argument validation. - src/Marten.AspNetCore.Testing/stream_paged_tests.cs (new): Alba HTTP-level tests against a new /minimal/issues/paged/{pageNumber}/{pageSize} endpoint.
- Adds a new 'Streaming a Paged JSON Envelope' section to docs/documents/querying/linq/paging.md describing StreamPagedJsonArray<T>() with a code example. - Adds a new StreamPaged<T> subsection (with a Wolverine.Http-style Minimal API example) to the 'Typed Streaming Result Types' table and section in docs/documents/aspnetcore.md, cross-linking to the paging.md section. - Verified clean with markdownlint-cli (--disable MD009) and cspell against docs/**/*.md.
erdtsieck
force-pushed
the
erdtsieck-streampaged-issue-5009
branch
2 times, most recently
from
July 22, 2026 10:01
af5cc07 to
a3126fe
Compare
This was referenced Jul 22, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds a new
StreamPaged<T>result type toMarten.AspNetCorethat streams a paged list of documents plus paging metadata as a single JSON envelope directly to the HTTP response, in one database round trip:{"pageNumber":3,"pageSize":25,"totalItemCount":1207,"pageCount":49,"hasNextPage":true,"hasPreviousPage":true,"items":[...]}Closes #5009.
Implementation
Marten.Linq.MartenLinqQueryable<T>.StreamPagedJsonArray- setsStatistics, appliesSkip/Take, delegates to the provider.MartenLinqQueryProvider.StreamPagedMany- builds the LINQ statement/command (which includescount(*) OVER() as total_rowsviaLinqConstants.StatsColumnwhenStatisticsis set), then executes via the session.QuerySession.StreamPagedMany+JsonStreamingExtensions.StreamPagedMany- readstotal_rowsfrom the first row of theDbDataReader, computespageCount/hasNextPage/hasPreviousPage(mirroringPagedList.ProcessResults), writes the envelope prefix, then streams each row's raw document JSON straight into theitemsarray without deserializing/reserializing documents.QueryableExtensions.StreamPagedJsonArray<T>(Marten core) - public entry point exposing the above.Marten.AspNetCore.QueryableExtensions.WritePaged<T>+StreamPaged<T>(IResult+IEndpointMetadataProvider, mirroringStreamMany<T>) - the minimal-API/Wolverine.Http-facing wrapper.Zero-row result sets produce
totalItemCount: 0,pageCount: 0, and an emptyitemsarray (count(*) OVER()is not present on any row when nothing matches).Tests
src/DocumentDbTests/Reading/Json/streaming_json_results.cs- 8 new[Fact]s covering first/middle/last/single page, no-hits, and argument validation (pageNumber < 1,pageSize < 1). All passing.src/Marten.AspNetCore.Testing/stream_paged_tests.cs(new) - Alba HTTP-level tests against a new/minimal/issues/paged/{pageNumber}/{pageSize}endpoint added toIssueService.Docs
docs/documents/querying/linq/paging.md- new "Streaming a Paged JSON Envelope" section describingStreamPagedJsonArray<T>().docs/documents/aspnetcore.md- addedStreamPaged<T>to the typed streaming result types table and a full usage subsection.markdownlint-cli(--disable MD009) andcspellagainstdocs/**/*.md.Test status
DocumentDbTests(both net9.0 and net10.0, run individually): all 8 newstream_paged_json_array_*tests pass.Marten.AspNetCore.Testing: the whole suite (including pre-existingstreaming_result_types_tests) currently fails to boot the Alba test host on this branch's base commit due to an unrelated, pre-existing environment issue (InvalidProjectionException: No source-generated dispatcher found for SingleStreamProjection<Order, Guid>). Verified this failure is not caused by this change - it reproduces identically on a clean, unmodified checkout ofmaster.Notes
dotnet testin parallel against the same shared Postgres schema can cause cross-run data contention/deadlocks unrelated to this feature; running each TFM individually avoids this and both pass cleanly.