Export (0) Print
Expand All

2.1.23 Model Function

A Function element is used to define or declare a user function. These functions are defined as child elements of the Schema element.

The following is an example of the Function element.

<Function Name="GetAge" ReturnType="Edm.Int32">
    <Parameter Name="Person" Type="Model.Person" />
    <DefiningExpression>
        Edm.DiffYears(Edm.CurrentDateTime(), Person.Birthday)
    </DefiningExpression>
</Function>

The following rules apply to the Function element:

  • The Function MUST have a Name attribute defined. The Name attribute is of type SimpleIdentifier. The Name attribute represents the name of this Function.

  • The Function MUST define a return type as an attribute or as a child element.

  • The Function MUST NOT contain both an attribute and a child element defining the return type.

  • If defined, the type of FunctionReturnType MUST be:

    • A scalar type, EntityType, or ComplexType that is in scope.

    • A collection of one of these scalar, EntityType, or ComplexType in-scope types.

    • A RowType element or a collection of RowType elements that is defined as a child element of ReturnType.

    • A ReferenceType element or a collection of ReferenceType elements that is defined as a child element of ReturnType.

  • A single DefiningExpression element can be defined for a given Function. A DefiningExpression is any expression that is intended to be the body of the function. The conceptual schema definition language (CSDL) file format does not specify rules and restrictions regarding what language is to be used for specifying function bodies.

  • All Functionparameters MUST be inbound.

  • Function can contain any number of AnnotationAttribute attributes. The full names of the AnnotationAttribute attributes MUST NOT collide.

  • Functions are declared as global items inside the Schema element.

  • Function can contain a maximum of one Documentation element.

  • The function parameters and return type MUST be of the following types:

    • A scalar type or a collection of scalar types.

    • An entity type or a collection of entity types.

    • A complex type or a collection of complex types.

    • A row type or a collection of row types.

    • A reference type or a collection of reference types.

  • Function can contain any number of Parameter elements.

  • Function can contain any number of AnnotationElement elements.

  • In CSDL 3.0, Function can contain any number of ValueAnnotation elements.

  • Parameter, DefiningExpression, and ReturnType can appear in any order.

  • AnnotationElement MUST be the last in the sequence of elements of a Function.

Function element table

All child elements MUST appear in the order indicated. For all child elements within a given choice, the child elements can be ordered arbitrarily.

 
Show:
© 2015 Microsoft