{"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/3a2006ef569de08368d59db5e1468aa8f407e4f8/src/EFCore.Relational/Infrastructure/RelationalModelValidator.cs#L2227-L2263","documentation":"Thrown inside ValidateNonTphMapping when two entity types in a non-TPH hierarchy resolve to the same View StoreObjectIdentifier. Like the table clash (426) but for view mappings — each type in TPT/TPC must map to a distinct view.","triggerScenarios":"Two types in a TPT/TPC hierarchy call ToView(\"SameView\"), producing the same view StoreObjectIdentifier for sibling types.","commonSituations":"Backing a TPT/TPC hierarchy with database views and reusing a view name across types; copy-pasting ToView calls; refactor that merged view names.","solutions":["Map each type to its own view name.","Switch to TPH if a single shared view is intended.","Remove conflicting ToView calls and let mapping differ per type."],"exampleFix":"// before\nmodelBuilder.UseTptMappingStrategy();\nmodelBuilder.Entity<Customer>().ToView(\"v_People\");\nmodelBuilder.Entity<Vendor>().ToView(\"v_People\"); // throws 427\n\n// after\nmodelBuilder.Entity<Customer>().ToView(\"v_Customers\");\nmodelBuilder.Entity<Vendor>().ToView(\"v_Vendors\");","handlingStrategy":"validation","validationCode":"foreach (var root in modelBuilder.Model.GetEntityTypes().Where(t => t.BaseType == null))\n{\n    var strategy = root.GetMappingStrategy();\n    if (strategy != RelationalAnnotationNames.TptMappingStrategy\n        && strategy != RelationalAnnotationNames.TpcMappingStrategy) continue;\n    var views = new HashSet<string>();\n    foreach (var et in root.GetDerivedTypesInclusive())\n    {\n        var so = StoreObjectIdentifier.Create(et, StoreObjectType.View);\n        if (so != null && !views.Add(so.Value.Name))\n            throw new InvalidOperationException($\"View '{so.Value.Name}' used by multiple types in {root.DisplayName()} hierarchy.\");\n    }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["In TPT/TPC, give each type a unique ToView name.","Use TPH if a single shared view is intended.","Add a view-collision check in your model test."],"tags":["ef-core","model-validation","mapping","inheritance","tpt","tpc","views"],"backgroundTag":null,"analyzedSha":"3a2006ef569de08368d59db5e1468aa8f407e4f8","analyzedAt":"2026-08-11T23:42:04.146Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}