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 precisions ('{precision1}' and '{precision2}').

What it means

Two properties sharing a column specify different Precision values (for decimal/numeric types). The validator cannot pick which precision to materialize and throws during model finalization. Thrown from ValidateCompatible via GetPrecision(storeObject) facet comparison.

Source

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

        }

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

        var currentPrecision = property.GetPrecision(storeObject);
        var previousPrecision = duplicateProperty.GetPrecision(storeObject);
        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(),

View on GitHub (pinned to dbf9771522)

Solutions

  1. Standardize on one (precision, scale) pair and apply HasPrecision(p,s) to both properties.
  2. Rename one column with HasColumnName if the two values legitimately need different precisions.
  3. Move one type to its own table via ToTable so the columns no longer share.

Example fix

// before
modelBuilder.Entity<Student>().Property(s => s.Score).HasPrecision(5, 2);
modelBuilder.Entity<Teacher>().Property(t => t.Score).HasPrecision(7, 3);
// after
modelBuilder.Entity<Student>().Property(s => s.Score).HasPrecision(7, 3);
modelBuilder.Entity<Teacher>().Property(t => t.Score).HasPrecision(7, 3);
Defensive patterns

Strategy: validation

Validate before calling

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

Try / catch

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

Prevention

When it happens

Trigger: A same-named decimal on sibling TPH types where one calls HasPrecision(18,2) and the other HasPrecision(10,4); an owned money property with precision set while the owner's matching column differs; table splitting with mismatched precision.

Common situations: Refactoring a financial Amount property to higher precision in one entity without updating the sibling; copying entity configs from another project where precision differs; mixing [Precision] data annotation with Fluent HasPrecision on different sides.

Related errors


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