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 that 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 cannot contain both an attribute and a child element that defines the return type.
If defined, the type of FunctionReturnType MUST be:
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 Function parameters have to be inbound.
Function can contain any number of AnnotationAttribute attributes. The full names of the AnnotationAttribute attributes cannot 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:
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 has to be the last in the sequence of elements of a Function.
All child elements are to appear in the order indicated. For all child elements within a given choice, the child elements can be ordered arbitrarily.