{"record":{"id":"570d70b20f3d7727","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/dbf9771522148d61a2467854921bd5dc6f6e6916/src/EFCore.Cosmos/Query/Internal/Expressions/StructuralTypeProjectionExpression.cs#L89-L125","documentation":"StructuralTypeProjectionExpression.BindProperty throws InvalidOperationException when the given IProperty is not declared on (or assignable to/from) the structural type being projected. The provider cannot read a JSON field for a property that does not belong to the projected entity/structural type.","triggerScenarios":"Binding a property belonging to an unrelated entity against the current projection — e.g. the translator tries to read Order.Customer.Name as a property of Order directly, or a custom translator binds the wrong IProperty.","commonSituations":"Misconfigured inheritance hierarchies (TPH) where a property is on a sibling type; custom translators passing the wrong IProperty; querying a property via a projection of a different structural type.","solutions":["Navigate through the correct path (e.g. bind Customer.Name via the Customer navigation, not as Order's own property).","Verify the entity/structural type in the projection contains the property; for inheritance, ensure the property is mapped on the correct hierarchy node.","In custom translators, pass the IProperty resolved from the structural type you are binding against."],"exampleFix":"// before: binding the wrong property to the wrong projection\nprojection.BindProperty(customerNameProperty, clientEval: false);\n\n// after: bind via the correct structural type's property\nvar customerProjection = orderProjection.BindNavigation(customerNav, false);\ncustomerProjection.BindProperty(customerNameProperty, clientEval: false);","handlingStrategy":"validation","validationCode":"// Verify the property belongs to the projected structural type before binding.\nstatic bool IsBindable(ITypeBase structuralType, IProperty p)\n    => structuralType.IsAssignableFrom(p.DeclaringType)\n       || p.DeclaringType.IsAssignableFrom(structuralType);","typeGuard":"static bool PropertyBelongsToProjection(ITypeBase projectionType, IProperty p)\n    => projectionType.IsAssignableFrom(p.DeclaringType)\n       || p.DeclaringType.IsAssignableFrom(projectionType);","tryCatchPattern":"try { var q = query.ToList(); }\ncatch (InvalidOperationException ex) when (ex.Message.Contains(\"Unable to bind\") && ex.Message.Contains(\"property\"))\n{ /* navigate to the correct structural type that owns the property */ }","preventionTips":["Bind properties only on the structural type that declares them.","For inheritance, project the derived type before binding its properties."],"tags":["cosmos","projection","binding","property"],"analyzedSha":"dbf9771522148d61a2467854921bd5dc6f6e6916","analyzedAt":"2026-08-06T20:46:03.226Z","schemaVersion":2},"datasetVersion":"2026-08-07T03:17:09.362Z"}