Skip to content

Case sensitivity issue with .NET 8 onward #96

@daniel-jann

Description

@daniel-jann

.NET 8 DbContext uses case insensitive fields with SQL Server, which can lead to failures when using keys that only differ in casing.

As described by ajcvickers, case sensitive comparers should be used:

// From .NET 8 onwards, string comparisons are case insensitive by default in EF Core.
// We need to explicitly set case sensitive comparers for Key and ResourceKey properties.
var caseSensitiveComparer = new ValueComparer<string>(
    (l, r) => string.Equals(l, r, StringComparison.Ordinal),
    v => v.GetHashCode(),
    v => v);

builder.Entity<LocalizationRecord>().Property(m => m.Key).Metadata.SetValueComparer(caseSensitiveComparer);
builder.Entity<LocalizationRecord>().Property(m => m.ResourceKey).Metadata.SetValueComparer(caseSensitiveComparer);

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions