Skip to content

Honor the configured identity in cursor paging validation - #5815

Merged
jeremydmiller merged 1 commit into
JasperFx:masterfrom
BinaryTENSHi:fix/5814-cursor-paging-fluent-identity
Nov 5, 2026
Merged

jeremydmiller merged 1 commit into
JasperFx:masterfrom
BinaryTENSHi:fix/5814-cursor-paging-fluent-identity

Conversation

@BinaryTENSHi

@BinaryTENSHi BinaryTENSHi commented Nov 4, 2026 •

Copy link
Copy Markdown
Contributor

Part of #5814. This covers the .Identity(x => x.Key) case on a plain Guid.

Cursor paging with strong-typed ids will come in a separate PR, so the issue should stay open.

Problem

ToJsonPageByCursorAsync validates that the last ordering is on the document identity using the static DocumentMapping.FindIdMember(typeof(T)). That only knows the Id naming convention and [Identity], so a document configured with Schema.For<T>().Identity(x => x.Key) throws InvalidOperationException even when it is ordered by its identity.

Fix

Read IdMember from the store's mapping of the query's source document type. Using the source type rather than T means a projected T, such as Select(x => x.FirstName), still gets the existing validation error instead of a mapping lookup for string.

Behavior change

A document with .Identity(x => x.Key) that also has an ordinary Id member used to pass validation when ordered by Id, even though nothing guarantees that member is unique. It is now rejected, and the error message names Key.

Testing

  • Added cursor_paging_with_fluent_identity, which pages through documents with tied sort keys. It failed with the issue's exception before the fix.
  • The cursor paging tests in DocumentDbTests, Marten.AspNetCore.Testing and Marten.NodaTime.Testing pass locally on net10.0.
  • Scalar projections, DTO projections, raw events, raw event data and subclass queries gave the same results before and after the fix, checked with a throwaway test.

🤖 Generated with Claude Code

ToJsonPageByCursorAsync checked the terminal ordering against the static
DocumentMapping.FindIdMember, which only knows the Id naming convention and
[Identity]. A document configured with Schema.For<T>().Identity(x => x.Key)
was therefore rejected with "requires the final OrderBy/ThenBy clause to be
on a member guaranteed to be unique" even when ordered by its identity.

Resolve the identity from the store's mapping of the query's source document
type instead.

Part of JasperFx#5814

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@BinaryTENSHi
BinaryTENSHi marked this pull request as draft November 4, 2026 16:09
@BinaryTENSHi
BinaryTENSHi marked this pull request as ready for review November 4, 2026 18:03
@jeremydmiller
jeremydmiller merged commit 6ba0701 into JasperFx:master Nov 5, 2026
32 checks passed
This was referenced Nov 6, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants