dotnet/efcore · error · InvalidOperationException

'{entityType1}.{property1}' and '{entityType2}.{property2}'

Error message

'{entityType1}.{property1}' and '{entityType2}.{property2}' are both mapped to column '{columnName}' in '{table}', but are configured with different scales ('{scale1}' and '{scale2}').

What it means

Two properties mapped to the same column specify different Scale values (the decimal places portion). Even if precision matches, scale must agree because the physical column's scale is a single value. Thrown from ValidateCompatible via GetScale(storeObject).

Source

Thrown at src/EFCore.Relational/Infrastructure/RelationalModelValidator.cs:1606

        if (currentPrecision != previousPrecision)
        {
            throw new InvalidOperationException(
                RelationalStrings.DuplicateColumnNamePrecisionMismatch(
                    duplicateProperty.DeclaringType.DisplayName(),
                    duplicateProperty.Name,
                    property.DeclaringType.DisplayName(),
                    property.Name,
                    columnName,
                    storeObject.DisplayName(),
                    currentPrecision,
                    previousPrecision));
        }

        var currentScale = property.GetScale(storeObject);
        var previousScale = duplicateProperty.GetScale(storeObject);
        if (currentScale != previousScale)
        {
            throw new InvalidOperationException(
                RelationalStrings.DuplicateColumnNameScaleMismatch(
                    duplicateProperty.DeclaringType.DisplayName(),
                    duplicateProperty.Name,
                    property.DeclaringType.DisplayName(),
                    property.Name,
                    columnName,
                    storeObject.DisplayName(),
                    currentScale,
                    previousScale));
        }

        if (property.IsConcurrencyToken != duplicateProperty.IsConcurrencyToken)
        {
            throw new InvalidOperationException(
                RelationalStrings.DuplicateColumnNameConcurrencyTokenMismatch(
                    duplicateProperty.DeclaringType.DisplayName(),
                    duplicateProperty.Name,
                    property.DeclaringType.DisplayName(),

View on GitHub (pinned to dbf9771522)

Solutions

  1. Pick one canonical scale and set it on both properties via HasPrecision(precision, scale).
  2. Use HasColumnName to separate the columns when scale genuinely differs.
  3. Split one entity to its own table via ToTable.

Example fix

// before
modelBuilder.Entity<Student>().Property(s => s.Amount).HasPrecision(18, 2);
modelBuilder.Entity<Teacher>().Property(t => t.Amount).HasPrecision(18, 4);
// after
modelBuilder.Entity<Student>().Property(s => s.Amount).HasPrecision(18, 4);
modelBuilder.Entity<Teacher>().Property(t => t.Amount).HasPrecision(18, 4);
Defensive patterns

Strategy: validation

Validate before calling

using (var ctx = new MyContext()) { ctx.Model.ToDebugString(); }
var a = ctx.Model.FindEntityType(typeof(Student))!.FindProperty("Amount")!.GetScale();
var b = ctx.Model.FindEntityType(typeof(Teacher))!.FindProperty("Amount")!.GetScale();
Debug.Assert(a == b, $"Scale mismatch: {a} vs {b}");

Try / catch

try { using var ctx = new MyContext(); _ = ctx.Model; }
catch (InvalidOperationException ex) when (ex.Message.Contains("different scales"))
{ log.Error("Scale mismatch on shared column: {Msg}", ex.Message); throw; }

Prevention

When it happens

Trigger: Sibling TPH types calling HasPrecision(18, 2) and HasPrecision(18, 4) respectively for the same column name; an owned decimal whose scale differs from the owner's mirrored column; table-splitting where the two entity classes set different scales.

Common situations: Changing scale on a financial column from 2 to 4 places in one entity only; converting a measurement value to higher resolution on one branch of a hierarchy; cross-team ownership of sibling entities causing divergence.

Related errors


AI-assisted analysis of dotnet/efcore@dbf9771522 (2026-08-06). Data as JSON: /api/errors/2f94262d4e34b1bb. Report an issue: GitHub.