Annotation Elements (CSDL)

Annotation elements in conceptual schema definition language (CSDL) are custom XML elements in the conceptual model. In addition to having valid XML structure, the following must be true of annotation elements:

  • Annotation elements must not be in any XML namespace that is reserved for CSDL.

  • More than one annotation element may be a child of a given CSDL element.

  • The fully-qualified names of any two annotation elements must not be the same.

  • Annotation elements must appear after all other child elements of a given CSDL element.

Annotation elements can be used to provide extra metadata about the elements in a conceptual model. Starting with the .NET Framework version 4, metadata contained in annotation elements can be accessed at runtime by using classes in the System.Data.Metadata.Edm namespace.


The following example shows an EntityType element with an annotation element (CustomElement). The example also show an annotation attribute applied to the entity type element. For more information, see Annotation Attributes (CSDL).

<Schema Namespace="SchoolModel" Alias="Self"
  <EntityContainer Name="SchoolEntities" annotation:LazyLoadingEnabled="true">
    <EntitySet Name="People" EntityType="SchoolModel.Person" />
  <EntityType Name="Person" xmlns:p=""
              p:CustomAttribute="Data here.">
      <PropertyRef Name="PersonID" />
    <Property Name="PersonID" Type="Int32" Nullable="false"
              annotation:StoreGeneratedPattern="Identity" />
    <Property Name="LastName" Type="String" Nullable="false"
              MaxLength="50" Unicode="true" FixedLength="false" />
    <Property Name="FirstName" Type="String" Nullable="false"
              MaxLength="50" Unicode="true" FixedLength="false" />
    <Property Name="HireDate" Type="DateTime" />
    <Property Name="EnrollmentDate" Type="DateTime" />
      Custom metadata.

The following code retrieves the metadata in the annotation element and writes it to the console:

Dim collection As New EdmItemCollection("School.csdl")
Dim workspace As New MetadataWorkspace()
Dim contentType As EdmType
workspace.TryGetType("Person", "SchoolModel", DataSpace.CSpace, contentType)
If contentType.MetadataProperties.Contains("") Then
    Dim annotationProperty As MetadataProperty = _
    Dim annotationValue As Object = annotationProperty.Value
End If
EdmItemCollection collection = new EdmItemCollection("School.csdl");
MetadataWorkspace workspace = new MetadataWorkspace();
EdmType contentType;
workspace.TryGetType("Person", "SchoolModel", DataSpace.CSpace, out contentType);
if (contentType.MetadataProperties.Contains(""))
    MetadataProperty annotationProperty =
    object annotationValue = annotationProperty.Value;

The code above assumes that the School.csdl file is in the project's output directory and that you have added the following Imports and Using statements to your project:

Imports System.Data.Metadata.Edm
using System.Data.Metadata.Edm;

See Also


Annotation Attributes (CSDL)
CSDL Specification

Other Resources

CSDL, SSDL, and MSL Specifications