Share via

Facebook x.com LinkedIn Email

model-defined function (Entity Data Model)

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)

    NoteNote:

    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.

Example

The diagram below shows a conceptual model with three entity types: Book, Publisher, and Author.

Ee382833.ModelWithPublishedDate(en-us,VS.100).gif

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>

See Also

Concepts

Entity Data Model Key Concepts

Entity Data Model

Entity Data Model: Primitive Data Types


  • Last updated on 2011年02月20日