Function Element (CSDL)
The Function element in conceptual schema definition language (CSDL) is used to define or declare functions in the conceptual model. A function is defined by using a DefiningExpression element. For more information, see How to: Define Custom Functions in the Conceptual Model.
A Function element can have the following child elements (in the order listed):
Documentation (zero or one element)
Parameter (zero or more elements)
DefiningExpression (zero or one element)
ReturnType (zero or one element)
Annotation elements (zero or more elements)
A return type for a function must be specified with either the ReturnType element or the ReturnType attribute (see below), but not both. The possible return types are any EdmSimpleType, entity type, complex type, row type, or ref type (or a collection of one of these types). For more information, see Conceptual Model Types (CSDL).
Applicable Attributes
The table below describes the attributes that can be applied to the Function element.
Attribute Name | Is Required | Value |
---|---|---|
Name |
Yes |
The name of the function. |
ReturnType |
No |
The type returned by the function. |
Note
Any number of annotation attributes (custom XML attributes) may be applied to the Function element. However, custom attributes may not belong to any XML namespace that is reserved for CSDL. The fully-qualified names for any two custom attributes cannot be the same.
Example
The following example uses a Function element to define a function that returns the number of years since an instructor was hired.
<Function Name="YearsSince" ReturnType="Edm.Int32">
<Parameter Name="date" Type="Edm.DateTime" />
<DefiningExpression>
Year(CurrentDateTime()) - Year(date)
</DefiningExpression>
</Function>
See Also
Concepts
Entity Framework Overview
CSDL Specification
FunctionImport Element (CSDL)
Other Resources
CSDL, SSDL, and MSL Specifications
ADO.NET Entity Data Model Tools
model-defined function (Entity Data Model)