CollectionType Element (CSDL)

The CollectionType element in conceptual schema definition language (CSDL) specifies that a function parameter or function return type is a collection. For more information about functions, see Function Element (CSDL). The CollectionType element can be a child of the Parameter element or the ReturnType element. The type of collection can be specified by using either the Type attribute or one of the following child elements:

  • CollectionType

  • ReferenceType

  • RowType

  • TypeRef

    Note

    A model will not validate if the type of a collection is specified with both the Type attribute and a child element.

Applicable Attributes

The following table describes the attributes that can be applied to the CollectionType element. Note that the DefaultValue, MaxLength, FixedLength, Precision, Scale, Unicode, and Collation attributes are only applicable to collections of EDMSimpleTypes. For more information, see Facets (CSDL) and Conceptual Model Types (CSDL).

Attribute Name Is Required Value

Type

No

The type of the collection.

Nullable

No

True (the default value) or False depending on whether the property can have a null value.

Ee476606.note(en-us,VS.100).gifNote:
In the version of CSDL indicated by the https://schemas.microsoft.com/ado/2006/04/edm namespace, a complex type property must have Nullable="False".

DefaultValue

No

The default value of the property.

MaxLength

No

The maximum length of the property value.

FixedLength

No

True or False depending on whether the property value will be stored as a fixed length string.

Precision

No

The precision of the property value.

Scale

No

The scale of the property value.

Unicode

No

True or False depending on whether the property value will be stored as a Unicode string.

Collation

No

A string that specifies the collating sequence to be used in the data source.

Note

Any number of annotation attributes (custom XML attributes) may be applied to the CollectionType 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 model-defined function that that uses a CollectionType element to specify that the function returns a collection of Person entity types (as specified with the ElementType attribute).

<Function Name="LastNamesAfter">
       <Parameter Name="someString" Type="Edm.String"/>
       <ReturnType>
            <CollectionType  ElementType="SchoolModel.Person"/>
       </ReturnType>
       <DefiningExpression>
            SELECT VALUE p 
            FROM SchoolEntities.People AS p 
            WHERE p.LastName >= someString
       </DefiningExpression>
</Function>

The following example shows a model-defined function that uses a CollectionType element to specify that the function returns a collection of rows (as specified in the RowType element).

<Function Name="LastNamesAfter">
  <Parameter Name="someString" Type="Edm.String" />
  <ReturnType>
   <CollectionType>
     <RowType>
       <Property Name="FirstName" Type="Edm.String" Nullable="false" />
       <Property Name="LastName" Type="Edm.String" Nullable="false" />
     </RowType>
   </CollectionType>
  </ReturnType>
  <DefiningExpression>
            SELECT VALUE ROW(p.FirstName, p.LastName)
            FROM SchoolEntities.People AS p
            WHERE p.LastName &gt;= somestring
  </DefiningExpression>
</Function>

The following example shows a model-defined function that uses the CollectionType element to specify that the function accepts as a parameter a collection of Department entity types.

<Function Name="GetAvgBudget">
     <Parameter Name="Departments">
         <CollectionType>
            <TypeRef Type="SchoolModel.Department"/>
         </CollectionType>
          </Parameter>
      <ReturnType Type="Collection(Edm.Decimal)"/>
      <DefiningExpression>
            SELECT VALUE AVG(d.Budget) FROM Departments AS d
      </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