{"record":{"id":"d762edc501db0fd9","repo":"dotnet/efcore","slug":"the-type-entitytype-is-not-mapped-to-the-store-d762ed","errorCode":null,"errorMessage":"The type '{entityType}' is not mapped to the store object '{table}'.","messagePattern":"The type '(.+?)' is not mapped to the store object '(.+?)'\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/EFCore.Relational/Metadata/Internal/TableBase.cs","lineNumber":234,"sourceCode":"        {\n            referencingForeignKeys = new SortedSet<IForeignKey>(ForeignKeyComparer.Instance);\n            ReferencingRowInternalForeignKeys[principalEntityType] = referencingForeignKeys;\n        }\n\n        ((SortedSet<IForeignKey>)referencingForeignKeys).Add(foreignKey);\n    }\n\n    /// <inheritdoc />\n    public virtual bool IsOptional(ITypeBase typeBase)\n    {\n        if (OptionalTypes == null)\n        {\n            CheckMappedType(typeBase);\n            return false;\n        }\n\n        return !OptionalTypes.TryGetValue(typeBase, out var optional)\n            ? throw new InvalidOperationException(\n                RelationalStrings.TableNotMappedEntityType(typeBase.DisplayName(), ((ITableBase)this).SchemaQualifiedName))\n            : optional;\n    }\n\n    private void CheckMappedType(ITypeBase typeBase)\n    {\n        if (EntityTypeMappings.All(m => m.TypeBase != typeBase)\n            && ComplexTypeMappings.All(m => m.TypeBase != typeBase))\n        {\n            throw new InvalidOperationException(\n                RelationalStrings.TableNotMappedEntityType(typeBase.DisplayName(), ((ITableBase)this).SchemaQualifiedName));\n        }\n    }\n\n    /// <summary>\n    ///     This is an internal API that supports the Entity Framework Core infrastructure and not subject to\n    ///     the same compatibility standards as public APIs. It may be changed or removed without notice in\n    ///     any release. You should only use it directly in your code with extreme caution and knowing that","sourceCodeStart":216,"sourceCodeEnd":252,"githubUrl":"https://github.com/dotnet/efcore/blob/dbf9771522148d61a2467854921bd5dc6f6e6916/src/EFCore.Relational/Metadata/Internal/TableBase.cs#L216-L252","documentation":"Thrown by TableBase.IsOptional when OptionalTypes has been populated (the table is shared/has optional mappings) but the queried typeBase is not present in it. It means the type is not mapped to this table among the optional-mapping set, so its optionality is undefined — EF refuses to silently default it.","triggerScenarios":"TableBase.cs:233-236: OptionalTypes != null and !OptionalTypes.TryGetValue(typeBase, out _). Reached via ITableBase.IsOptional(typeBase) during relational model finalization when a type that is not part of the table's optional mapping set is queried.","commonSituations":"An entity type that was expected to share a table but is not actually mapped to it (wrong ToTable, missing ownership, TPT misconfiguration); querying IsOptional for a type removed from the model; a derived type not participating in the shared table.","solutions":["Ensure the entity type is actually mapped to the table (ToTable / owned mapping / inheritance strategy).","Confirm the type is the same instance used in the table mapping (not a different IEntityType from another model).","If the type should not be on this table, redirect the call to the correct ITableBase for that type."],"exampleFix":"// before - OrderDetail expected to share Orders table but not mapped\nvar optional = table.IsOptional(orderDetailType); // throws\n\n// after - ensure mapping before querying\nmodelBuilder.Entity<Order>()\n    .OwnsOne(o => o.Detail, d => d.ToTable(\"Orders\"));\nvar optional = table.IsOptional(orderDetailType);","handlingStrategy":"validation","validationCode":"static bool IsMappedToTable(ITableBase table, ITypeBase type)\n    => table.EntityTypeMappings.Any(m => m.TypeBase == type)\n        || table.ComplexTypeMappings.Any(m => m.TypeBase == type);\n\n// before calling table.IsOptional(type):\nif (!IsMappedToTable(table, type))\n    throw new InvalidOperationException($\"{type.Name} is not mapped to {table.SchemaQualifiedName}.\");","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Ensure ToTable/ownership is configured before querying IsOptional.","Use the ITableBase resolved from the type's own mapping, not an unrelated table."],"tags":["relational","table-mapping","model-validation"],"analyzedSha":"dbf9771522148d61a2467854921bd5dc6f6e6916","analyzedAt":"2026-08-06T20:46:03.226Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}