{"record":{"id":"83920a9bb913c59b","repo":"dotnet/efcore","slug":"unable-to-bind-membertype-member-to-an-ent","errorCode":null,"errorMessage":"Unable to bind '{memberType}' '{member}' to an entity projection of '{entityType}'.","messagePattern":"Unable to bind '(.+?)' '(.+?)' to an entity projection of '(.+?)'\\.","errorType":"exception","errorClass":"InvalidOperationException","httpStatus":null,"severity":"error","filePath":"src/EFCore.Cosmos/Query/Internal/Expressions/StructuralTypeProjectionExpression.cs","lineNumber":107,"sourceCode":"    ///     doing so can result in application failures when updating to a new Entity Framework Core release.\n    /// </summary>\n    public virtual Expression Update(Expression @object)\n        => ReferenceEquals(@object, Object)\n            ? this\n            : new StructuralTypeProjectionExpression(@object, StructuralType);\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 Expression BindProperty(IProperty property, bool clientEval)\n    {\n        if (!StructuralType.IsAssignableFrom(property.DeclaringType)\n            && !property.DeclaringType.IsAssignableFrom(StructuralType))\n        {\n            throw new InvalidOperationException(\n                CosmosStrings.UnableToBindMemberToEntityProjection(\"property\", property.Name, StructuralType.DisplayName()));\n        }\n\n        if (!_propertyExpressionsMap.TryGetValue(property, out var expression))\n        {\n            expression = new ScalarAccessExpression(\n                Object, property.GetJsonPropertyName(), property.ClrType, property.GetTypeMapping());\n            _propertyExpressionsMap[property] = expression;\n        }\n\n        if (!clientEval\n            // TODO: We shouldn't be returning null from here. See issues #17670 and #14121.\n            && expression.PropertyName?.Length is null or 0)\n        {\n            // Non-persisted property can't be translated\n            return null!;\n        }\n","sourceCodeStart":89,"sourceCodeEnd":125,"githubUrl":"https://github.com/dotnet/efcore/blob/3a2006ef569de08368d59db5e1468aa8f407e4f8/src/EFCore.Cosmos/Query/Internal/Expressions/StructuralTypeProjectionExpression.cs#L89-L125","documentation":"StructuralTypeProjectionExpression.BindProperty throws when the supplied IProperty's declaring type is neither the same as, nor related to, the projection's StructuralType. The property does not belong to the entity being projected, so the provider cannot resolve a JSON path for it. This is normally raised by internal callers passing the wrong property.","triggerScenarios":"Internal translator code calls BindProperty with a property whose DeclaringType differs from the projection's StructuralType, e.g. binding a sibling-entity property against the wrong projection.","commonSituations":"Inheritance or TPH scenarios where a derived type's property is bound against a base-type projection; translator bugs after model changes.","solutions":["Verify the property's DeclaringType matches the projected StructuralType.","Call UpdateEntityType on the projection to switch to the correct derived type before binding.","Check that the entity being queried is the one that owns the property."],"exampleFix":"// before - property belongs to a derived type but projection is the base\nvar expr = baseProjection.BindProperty(derivedTypeProperty, clientEval: false);\n\n// after - narrow the projection first\nvar derived = baseProjection.UpdateEntityType(derivedType);\nvar expr = derived.BindProperty(derivedTypeProperty, clientEval: false);","handlingStrategy":"validation","validationCode":"// Before binding, ensure the property belongs to the structural type.\nstatic bool CanBindProperty(StructuralTypeProjectionExpression p, IProperty prop)\n    => p.StructuralType.IsAssignableFrom(prop.DeclaringType) || prop.DeclaringType.IsAssignableFrom(p.StructuralType);","typeGuard":"static bool PropertyBelongsToProjection(StructuralTypeProjectionExpression p, IProperty prop)\n    => p.StructuralType.IsAssignableFrom(prop.DeclaringType) || prop.DeclaringType.IsAssignableFrom(p.StructuralType);","tryCatchPattern":null,"preventionTips":["Always verify the property's DeclaringType matches the projection before binding.","Narrow projections with UpdateEntityType before binding derived-type properties.","Add internal assertions that catch mismatches during translator development."],"tags":["cosmos","projection","binding","internal"],"backgroundTag":null,"analyzedSha":"3a2006ef569de08368d59db5e1468aa8f407e4f8","analyzedAt":"2026-08-11T23:42:04.146Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}