{"record":{"id":"2debae21de32fdbf","repo":"dotnet/efcore","slug":"entitytype1-property1-and-entitytype2-pr-2debae","errorCode":null,"errorMessage":"'{entityType1}.{property1}' and '{entityType2}.{property2}' are both mapped to column '{columnName}' in '{table}', but are configured to use different data types ('{dataType1}' and '{dataType2}').","messagePattern":"'(.+?)\\.(.+?)' and '(.+?)\\.(.+?)' are both mapped to column '(.+?)' in '(.+?)', but are configured to use different data types \\('(.+?)' and '(.+?)'\\)\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/EFCore.Relational/Infrastructure/RelationalModelValidator.cs","lineNumber":1634,"sourceCode":"        }\n\n        if (property.IsConcurrencyToken != duplicateProperty.IsConcurrencyToken)\n        {\n            throw new InvalidOperationException(\n                RelationalStrings.DuplicateColumnNameConcurrencyTokenMismatch(\n                    duplicateProperty.DeclaringType.DisplayName(),\n                    duplicateProperty.Name,\n                    property.DeclaringType.DisplayName(),\n                    property.Name,\n                    columnName,\n                    storeObject.DisplayName()));\n        }\n\n        var currentTypeString = property.GetColumnType(storeObject);\n        var previousTypeString = duplicateProperty.GetColumnType(storeObject);\n        if (!string.Equals(currentTypeString, previousTypeString, StringComparison.OrdinalIgnoreCase))\n        {\n            throw new InvalidOperationException(\n                RelationalStrings.DuplicateColumnNameDataTypeMismatch(\n                    duplicateProperty.DeclaringType.DisplayName(),\n                    duplicateProperty.Name,\n                    property.DeclaringType.DisplayName(),\n                    property.Name,\n                    columnName,\n                    storeObject.DisplayName(),\n                    previousTypeString,\n                    currentTypeString));\n        }\n\n        var typeMapping = property.GetRelationalTypeMapping();\n        var duplicateTypeMapping = duplicateProperty.GetRelationalTypeMapping();\n        var currentProviderType = typeMapping.Converter?.ProviderClrType.UnwrapNullableType()\n            ?? typeMapping.ClrType;\n        var previousProviderType = duplicateTypeMapping.Converter?.ProviderClrType.UnwrapNullableType()\n            ?? duplicateTypeMapping.ClrType;\n        if (currentProviderType != previousProviderType","sourceCodeStart":1616,"sourceCodeEnd":1652,"githubUrl":"https://github.com/dotnet/efcore/blob/dbf9771522148d61a2467854921bd5dc6f6e6916/src/EFCore.Relational/Infrastructure/RelationalModelValidator.cs#L1616-L1652","documentation":"Two properties mapped to the same column specify different store column types via GetColumnType (e.g. 'varchar(50)' vs 'nvarchar(100)'). The validator compares column type strings case-insensitively and aborts if they differ. Thrown from ValidateCompatible.","triggerScenarios":"Sibling TPH types calling HasColumnType(\"varchar(50)\") and HasColumnType(\"nvarchar(100)\") on a same-named property; an owned entity and owner setting explicit types that don't match; table splitting where one side forces a custom column type.","commonSituations":"One team uses a custom column type for a Code property (e.g. 'citext') while another uses plain text; refactoring a property to a domain-specific type without updating siblings; mixing [Column(TypeName=...)] annotations with Fluent HasColumnType on different entities.","solutions":["Set HasColumnType to the identical string on both properties (case-insensitive match is required).","If the types genuinely differ, rename one column with HasColumnName.","Remove the explicit HasColumnType so both inherit the provider default for the CLR type."],"exampleFix":"// before\nmodelBuilder.Entity<Student>().Property(s => s.Code).HasColumnType(\"varchar(20)\");\nmodelBuilder.Entity<Teacher>().Property(t => t.Code).HasColumnType(\"nvarchar(20)\");\n// after\nmodelBuilder.Entity<Student>().Property(s => s.Code).HasColumnType(\"varchar(20)\");\nmodelBuilder.Entity<Teacher>().Property(t => t.Code).HasColumnType(\"varchar(20)\");","handlingStrategy":"validation","validationCode":"using (var ctx = new MyContext()) { ctx.Model.ToDebugString(); }\nvar a = ctx.Model.FindEntityType(typeof(Student))!.FindProperty(\"Code\")!.GetColumnType();\nvar b = ctx.Model.FindEntityType(typeof(Teacher))!.FindProperty(\"Code\")!.GetColumnType();\nDebug.Assert(string.Equals(a, b, StringComparison.OrdinalIgnoreCase), $\"ColumnType mismatch: {a} vs {b}\");","typeGuard":null,"tryCatchPattern":"try { using var ctx = new MyContext(); _ = ctx.Model; }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"different data types\"))\n{ log.Error(\"Column-type mismatch on shared column: {Msg}\", ex.Message); throw; }","preventionTips":["Avoid explicit HasColumnType on shared columns; let the provider derive the type from the CLR type and facets.","If explicit types are required, store them in constants shared by all configurations of that column.","Add a startup model-build test asserting column-type parity."],"tags":["ef-core","model-validation","column-type","shared-table","column-mapping"],"analyzedSha":"dbf9771522148d61a2467854921bd5dc6f6e6916","analyzedAt":"2026-08-06T20:46:03.226Z","schemaVersion":2},"datasetVersion":"2026-08-07T02:17:10.218Z"}