{"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/3a2006ef569de08368d59db5e1468aa8f407e4f8/src/EFCore.Relational/Infrastructure/RelationalModelValidator.cs#L1219-L1255","documentation":"Thrown when entity types sharing a table have different table-level comments (GetComment()) assigned. The validator collects the comment from the first entity, then for each connected entity compares its comment with the running value; mismatched non-null comments are rejected because they would produce contradictory ALTER TABLE ... COMMENT DDL.","triggerScenarios":"builder.Entity<A>().ToTable(\"X\", t => t.HasComment(\"A comment\")) and builder.Entity<B>().ToTable(\"X\", t => t.HasComment(\"B comment\")) with A and B sharing the table. The validator sees comment != null and nextComment != null and they are not equal.","commonSituations":"Adding a comment to one of several shared entities; merging owned entities where each sets a comment; refactoring an entity to owned without removing the old comment config.","solutions":["Set the same comment on every entity type sharing the table.","Set the comment only on one entity (the others leave it null) and let the validator propagate it.","Remove the conflicting HasComment call."],"exampleFix":"// before\nbuilder.Entity<Customer>().ToTable(\"Users\", t => t.HasComment(\"Customers\"));\nbuilder.Entity<User>().ToTable(\"Users\", t => t.HasComment(\"Users\"));\n\n// after\nbuilder.Entity<Customer>().ToTable(\"Users\", t => t.HasComment(\"Application users\"));\nbuilder.Entity<User>().ToTable(\"Users\"); // comment inherited","handlingStrategy":"validation","validationCode":"var byTable = model.GetEntityTypes().Where(e => e.GetTableName() != null).GroupBy(e => e.GetTableName());\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        Console.WriteLine($\"Table '{grp.Key}' has conflicting comments: {string.Join(\" | \", comments)}\");\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Set the table comment on exactly one entity type per shared table.","Avoid setting comments from automated scaffolding without reconciling across types.","Treat comments as a table-level concern, not per-entity."],"tags":["ef-core","table-sharing","model-validation","comments"],"backgroundTag":null,"analyzedSha":"3a2006ef569de08368d59db5e1468aa8f407e4f8","analyzedAt":"2026-08-11T23:42:04.146Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}