Annotation Attributes (CSDL)

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

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

  • More than one annotation attribute may be applied to a given CSDL element.

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

Annotation attributes can be used to provide extra metadata about the elements in a conceptual model. 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 attribute (CustomAttribute). The example also shows an annotation element applied to the entity type element. For more information, see Annotation Elements (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 attribute 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 Elements (CSDL)
CSDL Specification

Other Resources

CSDL, SSDL, and MSL Specifications