FunctionImport Element (CSDL)

The FunctionImport element in conceptual schema definition language (CSDL) represents a function that is defined in the data source but available to objects through the conceptual model. For example, a Function element in the storage model can be used to represent a stored procedure in a database. A FunctionImport element in the conceptual model represents the corresponding function in an Entity Framework application and is mapped to the storage model function by using the FunctionImportMapping element. When the function is called in the application, the corresponding stored procedure is executed in the database.

A common language runtime (CLR) method can be generated for an Entity Framework application based on a FunctionImport element. For more information, see Generated Code Overview (Entity Data Model Designer) and How to: Use EdmGen.exe to Generate Object-Layer Code.

The FunctionImport element can have the following child elements (in the order listed):

One Parameter element should be defined for each parameter that the function accepts.

Applicable Attributes

The table below describes the attributes that can be applied to the FunctionImport element.

Attribute Name Is Required Value

Name

Yes

The name of the imported function.

ReturnType

No

The type that the function returns. Do not use this attribute if the function does not return a value. Otherwise, the value must be an EDMSimpleType, an entity type, a complex type, or a collection of entity types or complex types that is within scope of the model.

Cc716710.note(en-us,VS.100).gifNote:
In a conceptual model for an application that targets the .NET Framework version 3.5 SP1, the return type must be a collection of EDMSimpleTypes or entity types.

EntitySet

No

If the function returns a collection of entity types, the value of the EntitySet must be the entity set to which the collection belongs. Otherwise, the EntitySet attribute must not be used.

Note

Any number of annotation attributes (custom XML attributes) may be applied to the FunctionImport 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 shows a FunctionImport element that accepts one parameter and returns a collection of entity types:

<FunctionImport Name="GetStudentGrades" 
                EntitySet="StudentGrade" 
                ReturnType="Collection(SchoolModel.StudentGrade)">
       <Parameter Name="StudentID" Mode="In" Type="Int32" />
</FunctionImport>

See Also

Concepts

Entity Framework Overview
CSDL Specification
EntityContainer Element (CSDL)

Other Resources

CSDL, SSDL, and MSL Specifications
ADO.NET Entity Data Model Tools
How to: Import a Stored Procedure