{"record":{"id":"417c03368e0861c2","repo":"dotnet/efcore","slug":"the-table-table-cannot-be-used-for-entity-type-417c03","errorCode":null,"errorMessage":"The table '{table}' cannot be used for entity type '{entityType}' since it is being used for entity type '{otherEntityType}' and the comment '{comment}' does not match the comment '{otherComment}'.","messagePattern":"The table '(.+?)' cannot be used for entity type '(.+?)' since it is being used for entity type '(.+?)' and the comment '(.+?)' does not match the comment '(.+?)'\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/EFCore.Relational/Infrastructure/RelationalModelValidator.cs","lineNumber":1237,"sourceCode":"                        throw new InvalidOperationException(\n                            RelationalStrings.IncompatibleTableKeyNameMismatch(\n                                table.DisplayName(),\n                                entityType.DisplayName(),\n                                nextEntityType.DisplayName(),\n                                key.GetName(table),\n                                key.Properties.Format(),\n                                otherKey.GetName(table),\n                                otherKey.Properties.Format()));\n                    }\n                }\n\n                var nextComment = nextEntityType.GetComment();\n                if (comment != null)\n                {\n                    if (nextComment != null\n                        && !comment.Equals(nextComment, StringComparison.Ordinal))\n                    {\n                        throw new InvalidOperationException(\n                            RelationalStrings.IncompatibleTableCommentMismatch(\n                                table.DisplayName(),\n                                entityType.DisplayName(),\n                                nextEntityType.DisplayName(),\n                                comment,\n                                nextComment));\n                    }\n                }\n                else\n                {\n                    comment = nextComment;\n                }\n\n                if (isExcluded.Equals(!nextEntityType.IsTableExcludedFromMigrations(table)))\n                {\n                    throw new InvalidOperationException(\n                        RelationalStrings.IncompatibleTableExcludedMismatch(\n                            table.DisplayName(),","sourceCodeStart":1219,"sourceCodeEnd":1255,"githubUrl":"https://github.com/dotnet/efcore/blob/dbf9771522148d61a2467854921bd5dc6f6e6916/src/EFCore.Relational/Infrastructure/RelationalModelValidator.cs#L1219-L1255","documentation":"Table-level comments (`.HasComment` on the entity/table, not column comments) must be consistent across all entity types sharing a table, because there is only one table object to carry the comment. The validator at line 1231-1244 compares comments between connected types during the BFS and throws if both are non-null and differ.","triggerScenarios":"Calling `.ToTable(\"T\", t => t.HasComment(\"...\"))` (or `.HasComment` via table builder) with different comment strings on two entity types mapped to the same table. Detected when both `comment` and `nextComment` are non-null and unequal.","commonSituations":"One team annotates the table via the principal entity, another via the owned/dependent entity with a different description; copy-paste of entity config leaving a stale comment; merging two models.","solutions":["Set the table comment on only one of the sharing entity types (the principal) and remove the others.","If comments are set on multiple types, make the string identical across all of them.","Use column-level comments (.Property(...).HasComment(...)) instead if different aspects need describing."],"exampleFix":"// before\nmodelBuilder.Entity<Order>()\n    .ToTable(\"Orders\", t => t.HasComment(\"Customer orders\"));\nmodelBuilder.Entity<OrderDetail>()\n    .ToTable(\"Orders\", t => t.HasComment(\"Order line items\"));\n\n// after - single source of truth for the table comment\nmodelBuilder.Entity<Order>()\n    .ToTable(\"Orders\", t => t.HasComment(\"Customer orders\"));\nmodelBuilder.Entity<OrderDetail>()\n    .ToTable(\"Orders\");","handlingStrategy":"validation","validationCode":"var byTable = modelBuilder.Model.GetEntityTypes()\n    .Where(e => !e.IsMappedToJson())\n    .GroupBy(e => (e.GetTableName(), e.GetSchema()))\n    .Where(g => g.Count() > 1);\nforeach (var grp in byTable)\n{\n    var comments = grp.Select(e => e.GetComment()).Where(c => c != null).Distinct().ToList();\n    if (comments.Count > 1)\n        throw new InvalidOperationException(\n            $\"Shared table '{grp.Key.Item1}' has mismatched comments: {string.Join(\" | \", comments)}\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Set the table comment (.ToTable(name, t => t.HasComment(...))) on exactly one type per shared table.","Use column comments (.Property(...).HasComment(...)) for per-property documentation.","Centralize table-comment configuration in a single helper to avoid divergent strings."],"tags":["ef-core","table-sharing","model-validation","configuration"],"analyzedSha":"dbf9771522148d61a2467854921bd5dc6f6e6916","analyzedAt":"2026-08-06T20:46:03.226Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}