{"record":{"id":"e769ecbf282338a3","repo":"dotnet/efcore","slug":"entitytype1-property1-and-entitytype2-pr-e769ec","errorCode":null,"errorMessage":"'{entityType1}.{property1}' and '{entityType2}.{property2}' are both mapped to column '{columnName}' in '{table}', but are configured to use different collations ('{collation1}' and '{collation2}').","messagePattern":"'(.+?)\\.(.+?)' and '(.+?)\\.(.+?)' are both mapped to column '(.+?)' in '(.+?)', but are configured to use different collations \\('(.+?)' and '(.+?)'\\)\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/EFCore.Relational/Infrastructure/RelationalModelValidator.cs","lineNumber":1764,"sourceCode":"        if (!currentComment.Equals(previousComment, StringComparison.Ordinal))\n        {\n            throw new InvalidOperationException(\n                RelationalStrings.DuplicateColumnNameCommentMismatch(\n                    duplicateProperty.DeclaringType.DisplayName(),\n                    duplicateProperty.Name,\n                    property.DeclaringType.DisplayName(),\n                    property.Name,\n                    columnName,\n                    storeObject.DisplayName(),\n                    previousComment,\n                    currentComment));\n        }\n\n        var currentCollation = property.GetCollation(storeObject) ?? \"\";\n        var previousCollation = duplicateProperty.GetCollation(storeObject) ?? \"\";\n        if (!currentCollation.Equals(previousCollation, StringComparison.Ordinal))\n        {\n            throw new InvalidOperationException(\n                RelationalStrings.DuplicateColumnNameCollationMismatch(\n                    duplicateProperty.DeclaringType.DisplayName(),\n                    duplicateProperty.Name,\n                    property.DeclaringType.DisplayName(),\n                    property.Name,\n                    columnName,\n                    storeObject.DisplayName(),\n                    previousCollation,\n                    currentCollation));\n        }\n\n        var currentColumnOrder = property.GetColumnOrder(storeObject);\n        var previousColumnOrder = duplicateProperty.GetColumnOrder(storeObject);\n        if (currentColumnOrder != previousColumnOrder)\n        {\n            throw new InvalidOperationException(\n                RelationalStrings.DuplicateColumnNameOrderMismatch(\n                    duplicateProperty.DeclaringType.DisplayName(),","sourceCodeStart":1746,"sourceCodeEnd":1782,"githubUrl":"https://github.com/dotnet/efcore/blob/3a2006ef569de08368d59db5e1468aa8f407e4f8/src/EFCore.Relational/Infrastructure/RelationalModelValidator.cs#L1746-L1782","documentation":"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).","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\nmodelBuilder.Entity<User>().Property(u => u.UserName).UseCollation(\"SQL_Latin1_General_CP1_CI_AS\");\nmodelBuilder.Entity<UserProfile>().Property(p => p.UserName).UseCollation(\"SQL_Latin1_General_CP1_CS_AS\"); // shared\n\n// after\nmodelBuilder.Entity<User>().Property(u => u.UserName).UseCollation(\"SQL_Latin1_General_CP1_CI_AS\");\nmodelBuilder.Entity<UserProfile>().Property(p => p.UserName).UseCollation(\"SQL_Latin1_General_CP1_CI_AS\");","handlingStrategy":"validation","validationCode":"foreach (var (col, props) in sharedColumnGroups)\n{\n    var collations = props.Select(p => p.GetCollation(storeObject) ?? \"\").Distinct(StringComparer.Ordinal).ToList();\n    if (collations.Count > 1)\n        Console.WriteLine($\"Column {col} has conflicting collations: {string.Join(\", \", collations)}\");\n}","typeGuard":null,"tryCatchPattern":"try { _ = db.Model; } catch (InvalidOperationException ex) when (ex.Message.Contains(\"different collations\")) { // align UseCollation/HasCollation on both properties }","preventionTips":["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."],"tags":["model-validation","column-mapping","collation","relational"],"backgroundTag":null,"analyzedSha":"3a2006ef569de08368d59db5e1468aa8f407e4f8","analyzedAt":"2026-08-11T23:42:04.146Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}