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 comments ('{comment1}' and '{comment2}'). What it means
Two properties mapped to the same column declare different column comments via HasComment. The physical column can carry only one comment, so EF requires them to match exactly (compared with StringComparison.Ordinal, so case and whitespace matter).
Solutions
- Set the identical HasComment text on both properties.
- Remove HasComment from one side so both fall back to empty.
- If distinct documentation is genuinely needed, remap one property to a distinct column.
Example fix
// before
modelBuilder.Entity<Customer>().Property(c => c.Ref).HasComment("Customer reference");
modelBuilder.Entity<CustomerFlags>().Property(f => f.Ref).HasComment("Customer ref"); // shared, case/wording differs
// after
modelBuilder.Entity<Customer>().Property(c => c.Ref).HasComment("Customer reference");
modelBuilder.Entity<CustomerFlags>().Property(f => f.Ref).HasComment("Customer reference"); Defensive patterns
Strategy: validation
Validate before calling
foreach (var (col, props) in sharedColumnGroups)
{
var comments = props.Select(p => p.GetComment(storeObject) ?? "").Distinct(StringComparer.Ordinal).ToList();
if (comments.Count > 1)
Console.WriteLine($"Column {col} has conflicting comments");
} Try / catch
try { _ = db.Model; } catch (InvalidOperationException ex) when (ex.Message.Contains("different comments")) { // align HasComment on both properties } Prevention
- Maintain column comments in one place; reference the same string on shared columns.
- Remember comments compare case-sensitively; standardize wording.
- Smoke-test the model at startup.
When it happens
Trigger: ValidateCompatible() reads property.GetComment(storeObject) and duplicateProperty.GetComment(storeObject) (null coerced to empty); an Ordinal inequality throws. Happens when two entities sharing a column each call HasComment with different text.
Common situations: Documentation refresh on one entity but not its table-splitting partner; localization of comments applied to only one side; scaffolding that imported comments only for the principal entity.
Related errors
- ' . ' and ' . ' are both mapped to column ' ' in ' ', but…
- ' . ' and ' . ' are both mapped to column ' ' in ' ', but…
- ' . ' and ' . ' are both mapped to column ' ' in ' ', but…
- ' . ' and ' . ' are both mapped to column ' ' in ' ', but…
- ' . ' and ' . ' are both mapped to column ' ' in ' ', but…
AI-assisted analysis of dotnet/efcore@3a2006ef56 (2026-08-11).
Data as JSON: /api/errors/04283b8b1ee08990.
Report an issue: GitHub.
Appendix: source
Thrown at src/EFCore.Relational/Infrastructure/RelationalModelValidator.cs:1748
if (!currentDefaultValueSql.Equals(previousDefaultValueSql, StringComparison.OrdinalIgnoreCase))
{
throw new InvalidOperationException(
RelationalStrings.DuplicateColumnNameDefaultSqlMismatch(
duplicateProperty.DeclaringType.DisplayName(),
duplicateProperty.Name,
property.DeclaringType.DisplayName(),
property.Name,
columnName,
storeObject.DisplayName(),
previousDefaultValueSql,
currentDefaultValueSql));
}
var currentComment = property.GetComment(storeObject) ?? "";
var previousComment = duplicateProperty.GetComment(storeObject) ?? "";
if (!currentComment.Equals(previousComment, StringComparison.Ordinal))
{
throw new InvalidOperationException(
RelationalStrings.DuplicateColumnNameCommentMismatch(
duplicateProperty.DeclaringType.DisplayName(),
duplicateProperty.Name,
property.DeclaringType.DisplayName(),
property.Name,
columnName,
storeObject.DisplayName(),
previousComment,
currentComment));
}
var currentCollation = property.GetCollation(storeObject) ?? "";
var previousCollation = duplicateProperty.GetCollation(storeObject) ?? "";
if (!currentCollation.Equals(previousCollation, StringComparison.Ordinal))
{
throw new InvalidOperationException(
RelationalStrings.DuplicateColumnNameCollationMismatch(
duplicateProperty.DeclaringType.DisplayName(),View on GitHub (pinned to 3a2006ef56)