A model-defined function is a function that is defined in a conceptual model. The body of a model-defined function is expressed in Entity SQL, which allows for the function to be expressed independently of rules or languages supported in the data source.
A definition for a model-defined function contains the following information:
A function name. (Required)
The type of the return value. (Optional)
If no return type is specified, the return value is void.
Parameter information. (Optional)
An Entity SQL expression that defines the body of the function.
Note that model-defined functions do not support output parameters. This restriction is in place so that model-defined functions can be composed.
The diagram below shows a conceptual model with three entity types:
The ADO.NET Entity Framework uses a domain-specific language (DSL) called conceptual schema definition language (CSDL) to define conceptual models. The following CSDL defines a function in the conceptual model that returns the numbers of years since an instance of a
Book (in the diagram above) was published.
<Function Name="GetYearsInPrint" ReturnType="Edm.Int32" > <Parameter Name="book" Type="BooksModel.Book" /> <DefiningExpression> Year(CurrentDateTime()) - Year(cast(book.PublishedDate as DateTime)) </DefiningExpression> </Function>