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 have different unicode configurations.

What it means

Two properties sharing a column disagree on the Unicode (IsUnicode) configuration. Unicode-ness changes the store type (e.g. nvarchar vs varchar), so conflicting settings would produce an ambiguous schema. EF validates this strictly rather than silently picking one.

Solutions

  1. Apply the same IsUnicode(...) value to both properties.
  2. Remove the explicit IsUnicode from one side so it uses the convention default (true for string).
  3. If they really need different encodings, map them to distinct columns.

Example fix

// before
modelBuilder.Entity<Account>().Property(a => a.Code).IsUnicode(true);
modelBuilder.Entity<AccountSettings>().Property(s => s.Code).IsUnicode(false); // shared column

// after
modelBuilder.Entity<Account>().Property(a => a.Code).IsUnicode(true);
modelBuilder.Entity<AccountSettings>().Property(s => s.Code).IsUnicode(true);
Defensive patterns

Strategy: validation

Validate before calling

foreach (var (col, props) in sharedColumnGroups)
{
    var flags = props.Select(p => p.IsUnicode(storeObject)).Distinct().ToList();
    if (flags.Count > 1)
        Console.WriteLine($"Column {col} has conflicting unicode settings");
}

Try / catch

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

Prevention

When it happens

Trigger: ValidateCompatible() checks property.IsUnicode(storeObject) != duplicateProperty.IsUnicode(storeObject) for two properties mapped to the same column. One is configured IsUnicode(true) and the other IsUnicode(false).

Common situations: Table-splitting where the owner uses a unicode column but the owned/detail type explicitly opts out of unicode; mixed data annotations; a database-first scaffold followed by manual edits that changed unicode on only one entity.

Related errors


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

Appendix: source

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

        var currentMaxLength = property.GetMaxLength(storeObject);
        var previousMaxLength = duplicateProperty.GetMaxLength(storeObject);
        if (currentMaxLength != previousMaxLength)
        {
            throw new InvalidOperationException(
                RelationalStrings.DuplicateColumnNameMaxLengthMismatch(
                    duplicateProperty.DeclaringType.DisplayName(),
                    duplicateProperty.Name,
                    property.DeclaringType.DisplayName(),
                    property.Name,
                    columnName,
                    storeObject.DisplayName(),
                    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,

View on GitHub (pinned to 3a2006ef56)