Repository navigation
EF-337: Fix wrong results for range/sort/aggregate over numeric properties stored as strings - #377
Merged
Merged
Conversation
…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.
ajcvickers
requested review from
adelinowona and
damieng
and removed request for
adelinowona
October 13, 2026 16:09
Contributor
There was a problem hiding this comment.
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.
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.
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.