Repository navigation
Closed
Copy link
Description
Bug description
SQLite decimal collation in EF Core fails when the application is running under a culture that uses a decimal separator different from . (dot), such as tr-TR which uses , (comma).
The current implementation parses decimal values using the application's current culture, which causes incorrect ordering and comparison of decimal values in SQLite when the culture is not invariant.
This results in incorrect sorting behavior for decimal columns depending on the active CultureInfo.
Your code
[ConditionalFact, UseCulture("tr-TR")]
public virtual void Can_query_OrderBy_decimal_with_Turkish_culture()
{
using var context = CreateContext();
var min = new BuiltInDataTypes
{
Id = 225,
PartitionId = 209,
TestDecimal = 1.05m,
TestDateTimeOffset = new DateTimeOffset(2018, 1, 1, 12, 0, 0, TimeSpan.Zero),
TestTimeSpan = TimeSpan.FromDays(1),
TestUnsignedInt64 = 0
};
context.Add(min);
var middle = new BuiltInDataTypes
{
Id = 226,
PartitionId = 209,
TestDecimal = 1.5m,
TestDateTimeOffset = new DateTimeOffset(2018, 1, 1, 12, 0, 0, TimeSpan.Zero),
TestTimeSpan = TimeSpan.FromDays(2),
TestUnsignedInt64 = 1
};
context.Add(middle);
var max = new BuiltInDataTypes
{
Id = 227,
PartitionId = 209,
TestDecimal = 2.5m,
TestDateTimeOffset = new DateTimeOffset(2018, 1, 1, 11, 0, 0, TimeSpan.FromHours(-2)),
TestTimeSpan = TimeSpan.FromDays(10),
TestUnsignedInt64 = long.MaxValue + 1ul
};
context.Add(max);
context.SaveChanges();
Fixture.TestSqlLoggerFactory.Clear();
var query = context.Set<BuiltInDataTypes>()
.Where(e => e.PartitionId == 209);
var results = query
.OrderBy(e => e.TestDecimal)
.Select(e => new { e.Id, e.TestDecimal })
.ToList();
AssertSql(
"""
SELECT "b"."Id", "b"."TestDecimal"
FROM "BuiltInDataTypes" AS "b"
WHERE "b"."PartitionId" = 209
ORDER BY "b"."TestDecimal" COLLATE EF_DECIMAL
""");
var expectedResults = query.AsEnumerable()
.OrderBy(e => e.TestDecimal)
.Select(e => new { e.Id, e.TestDecimal })
.ToList();
Assert.Equal(expectedResults.Count, results.Count);
for (var i = 0; i < expectedResults.Count; i++)
{
Assert.Equal(expectedResults[i].Id, results[i].Id);
Assert.Equal(expectedResults[i].TestDecimal, results[i].TestDecimal);
}
}Stack traces
Verbose output
EF Core version
10.0.0
Database provider
Microsoft.EntityFrameworkCore.Sqlite
Target framework
.NET 10.0
Operating system
Windows 11
IDE
Rider
Activity
roji commentedon Jan 1, 2026
Confirmed bug, not a regression.
AI Analysis
The issue is that the EF_DECIMAL collation in the SQLite provider uses the current culture to parse decimal strings stored in the database. When the application runs under a culture like tr-TR (where the decimal separator is , and the group separator is .), it incorrectly parses the invariant-formatted decimal strings (e.g., 1.05) stored by EF Core. In tr-TR, 1.05 is parsed as 105, leading to incorrect ordering.
Minimal repro
Fix SQLite decimal comparison with turkish culture (dotnet#37443)
docs(sqlite): record that EF 11 fixes only half the decimal collation…
docs(sqlite): link the upstream issue tracking the collation crash EF…
docs(sqlite): record that EF 11 fixes only half the decimal collation…
docs(sqlite): link the upstream issue tracking the collation crash EF…
test(efcore): order the decimal value objects of a .Value query in th…
docs(site): say that EF Core 10 on SQLite cannot order decimals under…
test(efcore): order the decimal value objects of a .Value query in th…
docs(site): say that EF Core 10 on SQLite cannot order decimals under…
test(efcore): order the decimal value objects of a .Value query in th…
docs(site): say that EF Core 10 on SQLite cannot order decimals under…