Skip to content

EF-337: Fix wrong results for range/sort/aggregate over numeric properties stored as strings - #377

Merged
ajcvickers merged 1 commit into
mongodb:mainfrom
ajcvickers:EF-337
Oct 14, 2026
Merged

ajcvickers merged 1 commit into
mongodb:mainfrom
ajcvickers:EF-337

Conversation

@ajcvickers

Copy link
Copy Markdown
Collaborator

An int/long/double/decimal property stored as a BSON string (HasBsonRepresentation(String), HasConversion(), or a built-in numeric cast with a string representation) had range comparisons, OrderBy and Sum/Min/Max/Average run against the stored string: Sum returned 0, Min/Max/OrderBy were lexicographic and Where(Price > 50) matched the wrong documents.

The EF-to-driver-LINQ bridge now reads such a property through Mql.Convert ($convert), so the server compares and aggregates the number. Equality, inequality, Equals, Contains and join keys keep the stored form (exact, index-friendly, and the driver cannot render decimal extremes or a $convert join key). Values written back by ExecuteUpdate also stay in the stored form, so a computed value is not written with the wrong BSON type.

A stored value that is not a valid number now fails range/sort/aggregate queries instead of being silently misordered or ignored; documented in BREAKING-CHANGES.md. Custom converters are not handled here.

…rties stored as strings

An int/long/double/decimal property stored as a BSON string (HasBsonRepresentation(String),
HasConversion<string>(), or a built-in numeric cast with a string representation) had range
comparisons, OrderBy and Sum/Min/Max/Average run against the stored string: Sum returned 0,
Min/Max/OrderBy were lexicographic and Where(Price > 50) matched the wrong documents.

The EF-to-driver-LINQ bridge now reads such a property through Mql.Convert ($convert), so the
server compares and aggregates the number. Equality, inequality, Equals, Contains and join keys
keep the stored form (exact, index-friendly, and the driver cannot render decimal extremes or a
$convert join key). Values written back by ExecuteUpdate also stay in the stored form, so a
computed value is not written with the wrong BSON type.

A stored value that is not a valid number now fails range/sort/aggregate queries instead of being
silently misordered or ignored; documented in BREAKING-CHANGES.md. Custom converters are not
handled here.
Copilot AI balanced review requested due to automatic review settings October 13, 2026 16:09
@ajcvickers
ajcvickers requested a review from a team as a code owner October 13, 2026 16:09
@ajcvickers
ajcvickers requested review from adelinowona and damieng and removed request for adelinowona October 13, 2026 16:09

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copilot review overview

0 open findings

🧠 Review effort: Balanced


💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

@damieng damieng left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@ajcvickers
ajcvickers merged commit 92f079e into mongodb:main Oct 14, 2026
16 checks passed
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.

3 participants