{"record":{"id":"2a71fa361ab12441","repo":"dotnet/efcore","slug":"the-entity-type-ownertype-is-not-mapped-so-by","errorCode":null,"errorMessage":"The entity type '{ownerType}' is not mapped, so by default the owned type '{navigation}.{ownedType}' will also be unmapped. If this is intended explicitly map the owned type to 'null', otherwise map it to a named '{storeObjectType}'.","messagePattern":"The entity type '(.+?)' is not mapped, so by default the owned type '(.+?)\\.(.+?)' will also be unmapped\\. If this is intended explicitly map the owned type to 'null', otherwise map it to a named '(.+?)'\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/EFCore.Relational/Infrastructure/RelationalModelValidator.cs","lineNumber":2225,"sourceCode":"    private static void ValidateNonTphMapping(IEntityType rootEntityType, StoreObjectType storeObjectType)\n    {\n        var isTpc = rootEntityType.GetMappingStrategy() == RelationalAnnotationNames.TpcMappingStrategy;\n        var derivedTypes = new Dictionary<StoreObjectIdentifier, IEntityType>();\n        foreach (var entityType in rootEntityType.GetDerivedTypesInclusive())\n        {\n            var storeObject = StoreObjectIdentifier.Create(entityType, storeObjectType);\n            if (storeObject == null)\n            {\n                var unmappedOwnedType = entityType.GetReferencingForeignKeys()\n                    .Where(fk => fk.IsOwnership)\n                    .Select(fk => fk.DeclaringEntityType)\n                    .FirstOrDefault(owned => StoreObjectIdentifier.Create(owned, storeObjectType) == null\n                        && ((IConventionEntityType)owned).GetStoreObjectConfigurationSource(storeObjectType) == null\n                        && !owned.IsMappedToJson());\n                if (unmappedOwnedType != null\n                    && entityType.GetDerivedTypes().Any(derived => StoreObjectIdentifier.Create(derived, storeObjectType) != null))\n                {\n                    throw new InvalidOperationException(\n                        RelationalStrings.UnmappedNonTPHOwner(\n                            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()));","sourceCodeStart":2207,"sourceCodeEnd":2243,"githubUrl":"https://github.com/dotnet/efcore/blob/3a2006ef569de08368d59db5e1468aa8f407e4f8/src/EFCore.Relational/Infrastructure/RelationalModelValidator.cs#L2207-L2243","documentation":"Thrown inside ValidateNonTphMapping when an entity type is itself not mapped to a store object (StoreObjectIdentifier.Create returns null), but it has derived types that ARE mapped, and it owns an owned type that is also unmapped and not mapped to JSON. EF refuses to silently leave the owned type unmapped and asks you to state your intent explicitly.","triggerScenarios":"A non-TPH hierarchy where an intermediate or base owner entity has no table/view mapping, has mapped derived types, and declares an owned type (HasOne/OwnsOne/OwnsMany) that is not explicitly mapped. The owner's unmapped state would cascade to the owned type.","commonSituations":"Abstract base types with owned collections; mixing TPT inheritance with owned types on an unmapped base; forgetting to map an owned type after splitting a hierarchy; refactor that left an owner without a table.","solutions":["Map the owner entity to a table/view so the owned type follows it.","Explicitly map the owned type to null to declare it should be unmapped: modelBuilder.Entity<Owner>().OwnsOne(o => o.Address, a => a.ToJson(null)) / SetTableName(null) as appropriate.","Map the owned type to its own named table/view explicitly.","Remove the ownership if it is not needed."],"exampleFix":"// before (owner unmapped, owned type inherits unmapped)\nmodelBuilder.Entity<OwnerBase>().HasNoKey();\nmodelBuilder.Entity<OwnerBase>().OwnsOne(o => o.Address); // throws 425\n\n// after - explicitly map owned type to null\nmodelBuilder.Entity<OwnerBase>().OwnsOne(o => o.Address, a =>\n{\n    a.ToTable(\"Addresses\"); // or a.ToJson(null) / explicit null mapping\n});","handlingStrategy":"validation","validationCode":"foreach (var entityType in modelBuilder.Model.GetEntityTypes())\n{\n    foreach (var sot in new[] { StoreObjectType.Table, StoreObjectType.View })\n    {\n        if (StoreObjectIdentifier.Create(entityType, sot) != null) continue;\n        var hasMappedDerived = entityType.GetDerivedTypes().Any(d => StoreObjectIdentifier.Create(d, sot) != null);\n        if (!hasMappedDerived) continue;\n        var unmappedOwned = entityType.GetReferencingForeignKeys()\n            .Where(fk => fk.IsOwnership)\n            .Select(fk => fk.DeclaringEntityType)\n            .FirstOrDefault(o => StoreObjectIdentifier.Create(o, sot) == null && !o.IsMappedToJson());\n        if (unmappedOwned != null)\n            throw new InvalidOperationException($\"Owner {entityType.DisplayName()} is unmapped with unmapped owned {unmappedOwned.DisplayName()} for {sot}; map explicitly.\");\n    }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["When mixing owned types with a non-TPH hierarchy, map the owner to a store object or explicitly null-map the owned type.","Review owned-type mappings after splitting an inheritance hierarchy.","Add a model test that finalizes the model to surface ownership/unmapped conflicts."],"tags":["ef-core","model-validation","mapping","owned-types","inheritance","tpt","tpc"],"backgroundTag":null,"analyzedSha":"3a2006ef569de08368d59db5e1468aa8f407e4f8","analyzedAt":"2026-08-11T23:42:04.146Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}