{"record":{"id":"ac996f347c7b4766","repo":"dotnet/efcore","slug":"both-entitytype-and-otherentitytype-are-ma-ac996f","errorCode":null,"errorMessage":"Both '{entityType}' and '{otherEntityType}' are mapped to the view '{view}'. All the entity types in a non-TPH hierarchy (one that doesn't have a discriminator) must be mapped to different views. See https://go.microsoft.com/fwlink/?linkid=2130430 for more information.","messagePattern":"Both '(.+?)' and '(.+?)' are mapped to the view '(.+?)'\\. All the entity types in a non-TPH hierarchy \\(one that doesn't have a discriminator\\) must be mapped 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":2245,"sourceCode":"                            entityType.DisplayName(),\n                            unmappedOwnedType.FindOwnership()!.PrincipalToDependent?.Name,\n                            unmappedOwnedType.DisplayName(),\n                            storeObjectType));\n                }\n\n                continue;\n            }\n\n            if (derivedTypes.TryGetValue(storeObject.Value, out var otherType))\n            {\n                switch (storeObjectType)\n                {\n                    case StoreObjectType.Table:\n                        throw new InvalidOperationException(\n                            RelationalStrings.NonTphTableClash(\n                                entityType.DisplayName(), otherType.DisplayName(), storeObject.Value.DisplayName()));\n                    case StoreObjectType.View:\n                        throw new InvalidOperationException(\n                            RelationalStrings.NonTphViewClash(\n                                entityType.DisplayName(), otherType.DisplayName(), storeObject.Value.DisplayName()));\n                    case StoreObjectType.InsertStoredProcedure:\n                    case StoreObjectType.DeleteStoredProcedure:\n                    case StoreObjectType.UpdateStoredProcedure:\n                        throw new InvalidOperationException(\n                            RelationalStrings.NonTphStoredProcedureClash(\n                                entityType.DisplayName(), otherType.DisplayName(), storeObject.Value.DisplayName()));\n                }\n            }\n\n            if (isTpc)\n            {\n                var rowInternalFk = entityType.FindDeclaredReferencingRowInternalForeignKeys(storeObject.Value)\n                    .FirstOrDefault();\n                if (rowInternalFk != null\n                    && entityType.GetDirectlyDerivedTypes().Any())\n                {","sourceCodeStart":2227,"sourceCodeEnd":2263,"githubUrl":"https://github.com/dotnet/efcore/blob/dbf9771522148d61a2467854921bd5dc6f6e6916/src/EFCore.Relational/Infrastructure/RelationalModelValidator.cs#L2227-L2263","documentation":"Same collision check as NonTphTableClash but for StoreObjectType.View: two types in a non-TPH (discriminator-less) hierarchy both resolve to the same view. Without a discriminator EF cannot distinguish rows, so the model is rejected.","triggerScenarios":"Two non-TPH sibling types both call ToView(\"V\") (or inherit the same view name) and collide in the derivedTypes dictionary during ValidateNonTphMapping(..., StoreObjectType.View).","commonSituations":"Read-only query scenarios mapping a hierarchy to a single shared view; copy-pasting ToView across derived types; scaffolding views without renaming per type.","solutions":["Map each derived type to its own view: modelBuilder.Entity<DerivedA>().ToView(\"v_DerivedA\").","If one shared view is intended, switch the hierarchy to TPH (set a discriminator) and keep all types on the same view.","Drop the ToView call on the derived type and rely on the default per-type view name."],"exampleFix":"// before\nmodelBuilder.Entity<Manager>().ToView(\"v_People\");\nmodelBuilder.Entity<Employee>().ToView(\"v_People\");\n\n// after\nmodelBuilder.Entity<Manager>().ToView(\"v_Managers\");\nmodelBuilder.Entity<Employee>().ToView(\"v_Employees\");","handlingStrategy":"validation","validationCode":"bool NoNonTphViewClash(DbContext context)\n{\n    foreach (var root in context.Model.GetEntityTypes()\n        .Where(e => e.BaseType == null && e.FindDiscriminatorProperty() == null && e.GetDerivedTypes().Any()))\n    {\n        var names = new HashSet<StoreObjectIdentifier>();\n        foreach (var et in root.GetDerivedTypesInclusive())\n        {\n            var so = StoreObjectIdentifier.Create(et, StoreObjectType.View);\n            if (so.HasValue && !names.Add(so.Value)) return false;\n        }\n    }\n    return true;\n}","typeGuard":null,"tryCatchPattern":"try { _ = context.Model; }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"non-TPH hierarchy\", StringComparison.Ordinal) && ex.Message.Contains(\"view '\", StringComparison.Ordinal))\n{\n    throw new InvalidOperationException(\"Two types in a TPT/TPC hierarchy share a view. Give each a distinct ToView, or switch to TPH.\", ex);\n}","preventionTips":["Give each TPT/TPC type its own ToView name.","Reserve shared views for TPH hierarchies only.","Add a model smoke test that materializes context.Model."],"tags":["ef-core","model-validation","inheritance","tpt","tpc","views","relational"],"analyzedSha":"dbf9771522148d61a2467854921bd5dc6f6e6916","analyzedAt":"2026-08-06T20:46:03.226Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}