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 to use different collations ('{collation1}' and '{collation2}'). What it means
Two properties sharing a column declare different collations via HasCollation / UseCollation. A physical column has exactly one collation; conflicting settings would produce contradictory ALTER COLUMN statements, so EF rejects the model. Compared with StringComparison.Ordinal (case-sensitive).
Solutions
- Apply the same HasCollation("...") to both properties (exact case match).
- Remove HasCollation from one side so both inherit the database/column default.
- If collations truly must differ, remap one property to its own column.
Example fix
// before
modelBuilder.Entity<User>().Property(u => u.UserName).UseCollation("SQL_Latin1_General_CP1_CI_AS");
modelBuilder.Entity<UserProfile>().Property(p => p.UserName).UseCollation("SQL_Latin1_General_CP1_CS_AS"); // shared
// after
modelBuilder.Entity<User>().Property(u => u.UserName).UseCollation("SQL_Latin1_General_CP1_CI_AS");
modelBuilder.Entity<UserProfile>().Property(p => p.UserName).UseCollation("SQL_Latin1_General_CP1_CI_AS"); Defensive patterns
Strategy: validation
Validate before calling
foreach (var (col, props) in sharedColumnGroups)
{
var collations = props.Select(p => p.GetCollation(storeObject) ?? "").Distinct(StringComparer.Ordinal).ToList();
if (collations.Count > 1)
Console.WriteLine($"Column {col} has conflicting collations: {string.Join(", ", collations)}");
} Try / catch
try { _ = db.Model; } catch (InvalidOperationException ex) when (ex.Message.Contains("different collations")) { // align UseCollation/HasCollation on both properties } Prevention
- Decide on one collation per shared string column and apply it everywhere.
- Remember collation names compare case-sensitively; copy the exact name.
- Smoke-test the model at startup.
When it happens
Trigger: ValidateCompatible() reads property.GetCollation(storeObject) and duplicateProperty.GetCollation(storeObject) (null coerced to empty); if they differ under Ordinal it throws. Common on string columns shared between entities.
Common situations: Case-sensitive vs case-insensitive collation mismatch ('SQL_Latin1_General_CP1_CI_AS' vs '..._CS_AS'); cross-database or cross-column collation applied inconsistently; scaffold then partial manual collation edits.
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/e769ecbf282338a3.
Report an issue: GitHub.
Appendix: source
Thrown at src/EFCore.Relational/Infrastructure/RelationalModelValidator.cs:1764
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(),
duplicateProperty.Name,
property.DeclaringType.DisplayName(),
property.Name,
columnName,
storeObject.DisplayName(),
previousCollation,
currentCollation));
}
var currentColumnOrder = property.GetColumnOrder(storeObject);
var previousColumnOrder = duplicateProperty.GetColumnOrder(storeObject);
if (currentColumnOrder != previousColumnOrder)
{
throw new InvalidOperationException(
RelationalStrings.DuplicateColumnNameOrderMismatch(
duplicateProperty.DeclaringType.DisplayName(),View on GitHub (pinned to 3a2006ef56)