Skip to content

Conversation

@salihozkara
Copy link
Contributor

@salihozkara salihozkara commented Dec 30, 2025

Fixes #37432

Summary of the changes

  • Fixed SQLite decimal collation to use invariant culture for parsing decimal values
  • Ensured correct decimal comparison in SQLite regardless of the application's current culture

Details

  • Updated SqliteConnection.CreateCollation to use CultureInfo.InvariantCulture when parsing decimal strings
  • Added test coverage for decimal ordering with Turkish culture (tr-TR) to verify the fix
  • The issue occurred when the application culture used a different decimal separator (e.g., comma in Turkish), causing incorrect sorting of decimal values

Fixes

This addresses the issue where SQLite decimal comparison would fail when the application was running under a culture that uses a different decimal separator (e.g., Turkish using comma instead of period).

dotnet-maestro bot and others added 3 commits December 22, 2025 19:59
[release/10.0] Source code updates from dotnet/dotnet
[release/10.0] Source code updates from dotnet/dotnet
Updated decimal parsing in EF_DECIMAL collation to use CultureInfo.InvariantCulture for consistent ordering across cultures. Added a test to verify correct ordering of decimal values under Turkish culture.
Copilot AI review requested due to automatic review settings December 30, 2025 16:55
@salihozkara salihozkara requested a review from a team as a code owner December 30, 2025 16:55
Eliminated the unnecessary 'using System.Globalization;' directive from BuiltInDataTypesSqliteTest.cs to clean up the code.
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR fixes a culture-specific bug in SQLite decimal comparison where using Turkish culture (or any culture with a different decimal separator) would cause incorrect sorting of decimal values.

  • Updated the EF_DECIMAL collation to parse decimal strings using CultureInfo.InvariantCulture
  • Added comprehensive test coverage for decimal ordering under Turkish culture (tr-TR)

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.

File Description
src/EFCore.Sqlite.Core/Storage/Internal/SqliteRelationalConnection.cs Updated the EF_DECIMAL collation to use InvariantCulture when parsing decimal strings, fixing culture-sensitive comparison issues
test/EFCore.Sqlite.FunctionalTests/BuiltInDataTypesSqliteTest.cs Added test with Turkish culture to verify decimal ordering works correctly regardless of application culture
Comment on lines +191 to +192
decimal.Parse(x, NumberStyles.Any, CultureInfo.InvariantCulture),
decimal.Parse(y, NumberStyles.Any, CultureInfo.InvariantCulture)));
Copy link

Copilot AI Dec 30, 2025

Choose a reason for hiding this comment

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

Using NumberStyles.Any for parsing decimal values from the database might be too permissive. NumberStyles.Any includes support for currency symbols, thousands separators, parentheses for negatives, and other formatting that shouldn't appear in SQLite's decimal storage format. Consider using a more restrictive NumberStyles value like NumberStyles.Number or NumberStyles.AllowDecimalPoint | NumberStyles.AllowLeadingSign to more accurately match the expected format of decimal values stored in SQLite.

Suggested change
decimal.Parse(x, NumberStyles.Any, CultureInfo.InvariantCulture),
decimal.Parse(y, NumberStyles.Any, CultureInfo.InvariantCulture)));
decimal.Parse(x, NumberStyles.Number, CultureInfo.InvariantCulture),
decimal.Parse(y, NumberStyles.Number, CultureInfo.InvariantCulture)));
Copilot uses AI. Check for mistakes.
Copy link
Member

Choose a reason for hiding this comment

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

@salihozkara this comment seems to make sense?

Adjusted the TestDecimal values for test entities in Can_query_OrderBy_decimal_with_Turkish_culture to ensure correct ordering and test coverage.
@AndriySvyryd AndriySvyryd changed the base branch from release/10.0 to main December 30, 2025 20:08
@AndriySvyryd AndriySvyryd self-assigned this Dec 30, 2025
Copilot AI review requested due to automatic review settings December 31, 2025 01:37
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

Copilot reviewed 3 out of 3 changed files in this pull request and generated no new comments.

@roji
Copy link
Member

roji commented Dec 31, 2025

Note: I have not opened an issue for this change, as it is a straightforward bug fix with clear scope and implementation.

Can you please open an issue? We try to always have an issue - especially when there's a bug - so that it's clear which release contains what, and when a bug was fixed, etc.

@salihozkara
Copy link
Contributor Author

Note: I have not opened an issue for this change, as it is a straightforward bug fix with clear scope and implementation.

Can you please open an issue? We try to always have an issue - especially when there's a bug - so that it's clear which release contains what, and when a bug was fixed, etc.

#37432

Copy link
Member

@roji roji left a comment

Choose a reason for hiding this comment

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

Thanks for submitting a fix! See below for some comments.


<PropertyGroup Label="Version settings">
<VersionPrefix>10.0.2</VersionPrefix>
<VersionPrefix>10.0.3</VersionPrefix>
Copy link
Member

Choose a reason for hiding this comment

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

Please revert, we handle version bumps separately.

Comment on lines +191 to +192
decimal.Parse(x, NumberStyles.Any, CultureInfo.InvariantCulture),
decimal.Parse(y, NumberStyles.Any, CultureInfo.InvariantCulture)));
Copy link
Member

Choose a reason for hiding this comment

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

@salihozkara this comment seems to make sense?

}

[ConditionalFact, UseCulture("tr-TR")]
public virtual void Can_query_OrderBy_decimal_with_Turkish_culture()
Copy link
Member

Choose a reason for hiding this comment

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

Can you please reduce this test to the bare minimum, removing all the unneeded stuff? Check out the minimal repro posted here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

3 participants