dotnet/efcore · error · InvalidOperationException

' . ' and ' . ' are both mapped to column ' ' in ' ', but…

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 mapped to the same column declare different numeric precisions via HasPrecision(precision, scale). Precision is the total digit count of a decimal/numeric column; because the column is shared, EF cannot reconcile two different precisions and throws rather than silently widening or narrowing one side.

Solutions

  1. Call HasPrecision(p, s) on both properties with identical precision.
  2. Pick the broader precision and apply it to both sides to avoid silent truncation.
  3. Remap one property to its own column if different precision is genuinely needed.

Example fix

// before
modelBuilder.Entity<Invoice>().Property(i => i.Amount).HasPrecision(18, 2);
modelBuilder.Entity<InvoiceTax>().Property(t => t.Amount).HasPrecision(12, 2); // shared column

// after
modelBuilder.Entity<Invoice>().Property(i => i.Amount).HasPrecision(18, 2);
modelBuilder.Entity<InvoiceTax>().Property(t => t.Amount).HasPrecision(18, 2);
Defensive patterns

Strategy: validation

Validate before calling

foreach (var (col, props) in sharedColumnGroups)
{
    var precisions = props.Select(p => p.GetPrecision(storeObject)).Distinct().ToList();
    if (precisions.Count > 1)
        Console.WriteLine($"Column {col} has conflicting precisions: {string.Join(", ", precisions)}");
}

Try / catch

try { _ = db.Model; } catch (InvalidOperationException ex) when (ex.Message.Contains("different precisions")) { // align HasPrecision on both properties }

Prevention

When it happens

Trigger: ValidateCompatible() reads property.GetPrecision(storeObject) and duplicateProperty.GetPrecision(storeObject) and they differ. Happens when two entities sharing a column each call HasPrecision with different first arguments.

Common situations: Money/rate fields shared between an owned detail and its owner, each set to different precisions; scaffold then manual decimal tweaks that touched only one entity; domain refactor splitting an entity but leaving inconsistent precision.

Related errors


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

Appendix: 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 3a2006ef56)