{"record":{"id":"5ceb51bf148cb73f","repo":"dotnet/efcore","slug":"entitytype-is-mapped-to-the-view-view-whil","errorCode":null,"errorMessage":"'{entityType}' is mapped to the view '{view}' while '{otherEntityType}' is mapped to the view '{otherView}'. Map all the entity types in the hierarchy to the same view, or remove the discriminator and map them all to different views. See https://go.microsoft.com/fwlink/?linkid=2130430 for more information.","messagePattern":"'(.+?)' is mapped to the view '(.+?)' while '(.+?)' is mapped to the view '(.+?)'\\. Map all the entity types in the hierarchy to the same view, or remove the discriminator and map them all to different views\\. See https://go\\.microsoft\\.com/fwlink/\\?linkid=2130430 for more information\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/EFCore.Relational/Infrastructure/RelationalModelValidator.cs","lineNumber":2335,"sourceCode":"                    {\n                        throw new InvalidOperationException(\n                            RelationalStrings.StoredProcedureTphDuplicate(\n                                entityType.DisplayName(), rootEntityType.DisplayName(), rootId?.DisplayName()));\n                    }\n                }\n\n                continue;\n            }\n\n            switch (storeObjectType)\n            {\n                case StoreObjectType.Table:\n                    throw new InvalidOperationException(\n                        RelationalStrings.TphTableMismatch(\n                            entityType.DisplayName(), entityId.Value.DisplayName(),\n                            rootEntityType.DisplayName(), rootId?.DisplayName()));\n                case StoreObjectType.View:\n                    throw new InvalidOperationException(\n                        RelationalStrings.TphViewMismatch(\n                            entityType.DisplayName(), entityId.Value.DisplayName(),\n                            rootEntityType.DisplayName(), rootId?.DisplayName()));\n                case StoreObjectType.Function:\n                    throw new InvalidOperationException(\n                        RelationalStrings.TphDbFunctionMismatch(\n                            entityType.DisplayName(), entityId.Value.DisplayName(),\n                            rootEntityType.DisplayName(), rootId?.DisplayName()));\n                case StoreObjectType.InsertStoredProcedure:\n                case StoreObjectType.DeleteStoredProcedure:\n                case StoreObjectType.UpdateStoredProcedure:\n                    throw new InvalidOperationException(\n                        RelationalStrings.TphStoredProcedureMismatch(\n                            entityType.DisplayName(), entityId.Value.DisplayName(),\n                            rootEntityType.DisplayName(), rootId?.DisplayName()));\n            }\n        }\n    }","sourceCodeStart":2317,"sourceCodeEnd":2353,"githubUrl":"https://github.com/dotnet/efcore/blob/3a2006ef569de08368d59db5e1468aa8f407e4f8/src/EFCore.Relational/Infrastructure/RelationalModelValidator.cs#L2317-L2353","documentation":"Thrown inside ValidateTphMapping when a derived type resolves to a different View StoreObjectIdentifier than the root. TPH requires all types in the hierarchy to share the same view; mapping a derived type to another view is rejected.","triggerScenarios":"A TPH hierarchy where a derived type calls ToView(\"OtherView\") (or is otherwise mapped to a different view than the root).","commonSituations":"Adding ToView on a derived type under TPH; layered read-model views per type; refactor that diverged view names.","solutions":["Remove the ToView override on the derived type so it uses the root's view.","Switch the hierarchy to TPT/TPC if separate views are intended.","Map the root to the same view as the derived types."],"exampleFix":"// before\nmodelBuilder.Entity<Person>().ToView(\"v_People\");\nmodelBuilder.Entity<Customer>().ToView(\"v_Customers\"); // throws 433\n\n// after (separate views -> TPT)\nmodelBuilder.UseTptMappingStrategy();\nmodelBuilder.Entity<Person>().ToView(\"v_People\");\nmodelBuilder.Entity<Customer>().ToView(\"v_Customers\");","handlingStrategy":"validation","validationCode":"foreach (var root in modelBuilder.Model.GetEntityTypes().Where(t => t.BaseType == null))\n{\n    if (root.FindDiscriminatorProperty() == null) continue;\n    var rootSo = StoreObjectIdentifier.Create(root, StoreObjectType.View);\n    if (rootSo == null) continue;\n    foreach (var et in root.GetDerivedTypes())\n    {\n        var so = StoreObjectIdentifier.Create(et, StoreObjectType.View);\n        if (so != null && so.Value != rootSo.Value)\n            throw new InvalidOperationException($\"{et.DisplayName()} view {so.Value.DisplayName()} differs from root view {rootSo.Value.DisplayName()} (TPH).\");\n    }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["In TPH, do not call ToView on derived types.","Switch to TPT/TPC if separate views are intended.","Add a model test asserting view consistency across a TPH hierarchy."],"tags":["ef-core","model-validation","mapping","inheritance","tph","views"],"backgroundTag":null,"analyzedSha":"3a2006ef569de08368d59db5e1468aa8f407e4f8","analyzedAt":"2026-08-11T23:42:04.146Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}