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 have different fixed length configuration.

What it means

Two properties mapped to the same column disagree on the fixed-length facet (IsFixedLength: nchar/char vs nvarchar/varchar). The validator cannot reconcile the difference and aborts model finalization. Thrown from ValidateCompatible during the shared-table check.

Source

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

                    previousMaxLength,
                    currentMaxLength));
        }

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

        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(),

View on GitHub (pinned to dbf9771522)

Solutions

  1. Apply IsFixedLength consistently (or remove it from both) so the two properties agree.
  2. Rename one side with HasColumnName so the columns no longer collide.
  3. Split the entity into its own table via ToTable if the facet legitimately must differ.

Example fix

// before
modelBuilder.Entity<Student>().Property(s => s.Code).IsFixedLength();
modelBuilder.Entity<Teacher>().Property(t => t.Code); // not fixed-length
// after
modelBuilder.Entity<Student>().Property(s => s.Code).IsFixedLength();
modelBuilder.Entity<Teacher>().Property(t => t.Code).IsFixedLength();
Defensive patterns

Strategy: validation

Validate before calling

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

Try / catch

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

Prevention

When it happens

Trigger: A same-named property on sibling TPH types where one calls IsFixedLength() (or [FixedLength]) and the other does not; an owned entity and its owner disagreeing on fixed-length; table splitting where one entity marks a shared column fixed-length.

Common situations: Introducing a fixed-length code (e.g. for ISO currency codes) on one branch of a hierarchy while the matching column on a sibling remains variable-length; cross-provider porting where one provider defaults to fixed-length for char(n).

Related errors


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