Udostępnij za pośrednictwem


DefiningExpression Element (CSDL)

The DefiningExpression element in conceptual schema definition language (CSDL) contains an Entity SQL expression that defines a function in the conceptual model. For more information, see Function Element (CSDL) and Entity SQL Language.

Note

For validation purposes, a DefiningExpression element can contain arbitrary content. However, the Entity Framework will throw an exception at runtime if a DefiningExpression element does not contain valid Entity SQL.

Applicable Attributes

Any number of annotation attributes (custom XML attributes) may be applied to the DefiningExpression 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 DefiningExpression element to define a function that returns the number of years since a book was published. The content of the DefiningExpression element is written in Entity SQL.

<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 Framework Overview
CSDL Specification
FunctionImport Element (CSDL)

Other Resources

CSDL, SSDL, and MSL Specifications
ADO.NET Entity Data Model Tools