{"record":{"id":"0b89c549a1b69188","repo":"dotnet/efcore","slug":"the-specified-entity-type-derivedtype-is-not-d","errorCode":null,"errorMessage":"The specified entity type '{derivedType}' is not derived from '{entityType}'.","messagePattern":"The specified entity type '(.+?)' is not derived from '(.+?)'\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/EFCore.Cosmos/Query/Internal/Expressions/StructuralTypeProjectionExpression.cs","lineNumber":293,"sourceCode":"            return BindComplexProperty(complex, clientEval);\n        }\n\n        // Entity member not found\n        propertyBase = null;\n        return null;\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\n    ///     doing so can result in application failures when updating to a new Entity Framework Core release.\n    /// </summary>\n    public virtual StructuralTypeProjectionExpression UpdateEntityType(IEntityType derivedType)\n        => StructuralType is not IEntityType entityType\n            ? throw new UnreachableException($\"{nameof(UpdateEntityType)} called on non-entity type '{StructuralType.DisplayName()}'\")\n            : !derivedType.GetAllBaseTypes().Contains(StructuralType)\n                ? throw new InvalidOperationException(\n                    CosmosStrings.InvalidDerivedTypeInEntityProjection(\n                        derivedType.DisplayName(), StructuralType.DisplayName()))\n                : new StructuralTypeProjectionExpression(Object, derivedType);\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\n    ///     doing so can result in application failures when updating to a new Entity Framework Core release.\n    /// </summary>\n    void IPrintableExpression.Print(ExpressionPrinter expressionPrinter)\n        => expressionPrinter.Visit(Object);\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\n    ///     doing so can result in application failures when updating to a new Entity Framework Core release.","sourceCodeStart":275,"sourceCodeEnd":311,"githubUrl":"https://github.com/dotnet/efcore/blob/3a2006ef569de08368d59db5e1468aa8f407e4f8/src/EFCore.Cosmos/Query/Internal/Expressions/StructuralTypeProjectionExpression.cs#L275-L311","documentation":"UpdateEntityType throws InvalidDerivedTypeInEntityProjection when the supplied 'derived type' does not have the projection's current StructuralType in its base-type chain. The provider was asked to narrow a projection to a derived entity type, but the inheritance relationship does not hold. StructuralType must already be an IEntityType (otherwise an UnreachableException is raised).","triggerScenarios":"OfType<T>() or inheritance materialization where the requested type is not actually a subtype of the projection's current entity type.","commonSituations":"Calling OfType<T>() with a type outside the queried entity's hierarchy; misconfigured inheritance hierarchies; passing an unrelated entity type to a projection-narrowing API.","solutions":["Ensure the type passed to UpdateEntityType is a genuine subtype of the current StructuralType.","Verify your inheritance hierarchy is configured (HasBaseType / TPH configuration).","Confirm OfType<T>() is called against a set whose base type is an ancestor of T."],"exampleFix":"// before - Animal is not derived from Vehicle\nvar q = db.Set<Vehicle>().OfType<Animal>();\n\n// after - use a real derived type\nvar q = db.Set<Vehicle>().OfType<Car>();","handlingStrategy":"validation","validationCode":"static bool IsDerivedFrom(IEntityType baseType, IEntityType derived)\n    => derived.GetAllBaseTypes().Contains(baseType);\n\n// before calling UpdateEntityType\nif (!IsDerivedFrom(projection.StructuralType as IEntityType, derivedType))\n    throw new InvalidOperationException($\"{derivedType.Name} is not derived from {projection.StructuralType.DisplayName()}\");","typeGuard":"static bool IsValidDerivedType(IEntityType current, IEntityType derived)\n    => derived.GetAllBaseTypes().Contains(current);","tryCatchPattern":null,"preventionTips":["Verify the inheritance chain before calling OfType<T> or UpdateEntityType.","Validate the hierarchy configuration in OnModelCreating.","Add a runtime check that asserts derivedType.GetAllBaseTypes() contains the current type."],"tags":["cosmos","inheritance","projection"],"backgroundTag":null,"analyzedSha":"3a2006ef569de08368d59db5e1468aa8f407e4f8","analyzedAt":"2026-08-11T23:42:04.146Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}