2.64.1 Context Entity and Cardinality

Each expression is evaluated within the context of a specific entity. This entity is referred to as the context entity. Within the expression, attribute references (AttributeRef elements) can only be to attributes contained by the current entity context or by any entity in the same inheritance hierarchy as the current entity context. Similarly, entity references (EntityRef elements) can only be to the current entity context or one related by inheritance.

For grouping expressions, the context entity is the base entity of the hierarchy.

For grouping detail expressions, the context entity is the entity specified by the grouping expression, which is always an EntityRef element for grouping detail expressions.

For measure expressions, the context entity is the base entity of the measure group.

For hierarchy filter expressions, the context entity is the base entity of the hierarchy.

For calculated attributes, the context entity depends on where it is used in the query just like subexpressions.

For subexpressions, the context entity depends on the combination of the containing context entity and the path.

Paths to subcomponents of the expression start in the context entity for that expression. Each PathItem element MUST be meaningful in the current context. For the RolePathItem element, this means it MUST be a role contained in the context entity.

Each PathItem element changes the current context entity. For the RolePathItem element, the new context entity is the target entity of the role.

In addition, a PathItem element can change the cardinality of the expression’s value. For the RolePathItem element, if the cardinality of the role is "Many" or "OptionalMany", the expression’s value is a set. Note that if the contained value was already a set rather than a scalar, the resulting value is not a set of sets. Instead, the individual contained sets are grouped and unioned into larger sets.