Schema Element (CSDL)

The Schema element is the root element of a conceptual model definition. It contains definitions for the objects, functions, and containers that make up a conceptual model.

The Schema element may contain zero or more of the following child elements:

A Schema element may contain zero or one Annotation elements.

Note

The Function element and annotation elements are only allowed in conceptual models for applications that target the .NET Framework version 4 or later. The XML namespace for such models is https://schemas.microsoft.com/ado/2008/09/edm.

The Schema element uses the Namespace attribute to define the namespace for the entity type, complex type, and association objects in a conceptual model. Within a namespace, no two objects can have the same name. Namespaces can span multiple Schema elements and multiple .csdl files.

A conceptual model namespace is different from the XML namespace of the Schema element. A conceptual model namespace (as defined by the Namespace attribute) is a logical container for entity types, complex types, and association types. The XML namespace (indicated by the xmlns attribute) of a Schema element is the default namespace for child elements and attributes of the Schema element. XML namespaces of the form https://schemas.microsoft.com/ado/YYYY/MM/edm (where YYYY and MM represent a year and month respectively) are reserved for CSDL. Custom elements and attributes cannot be in namespaces that have this form.

Applicable Attributes

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

Attribute Name Is Required Value

Namespace

Yes

The namespace of the conceptual model. The value of the Namespace attribute is used to form the fully qualified name of a type. For example, if an EntityType named Customer is in the Simple.Example.Model namespace, then the fully qualified name of the EntityType is SimpleExampleModel.Customer.

The following strings cannot be used as the value for the Namespace attribute: System, Transient, or Edm. The value for the Namespace attribute cannot be the same as the value for the Namespace attribute in the SSDL Schema element.

Alias

No

An identifier used in place of the namespace name. For example, if an EntityType named Customer is in the Simple.Example.Model namespace and the value of the Alias attribute is Model, then you can use Model.Customer as the fully qualified name of the EntityType.

Note

Any number of annotation attributes (custom XML attributes) may be applied to the Schema 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 Schema element that contains an EntityContainer element, two EntityType elements, and one Association element.

<Schema xmlns="https://schemas.microsoft.com/ado/2008/09/edm" 
     xmlns:cg="https://schemas.microsoft.com/ado/2006/04/codegeneration"
     xmlns:store="https://schemas.microsoft.com/ado/2007/12/edm/EntityStoreSchemaGenerator" 
      Namespace="ExampleModel" Alias="Self">
        <EntityContainer Name="ExampleModelContainer">
          <EntitySet Name="Customers" 
                     EntityType="ExampleModel.Customer" />
          <EntitySet Name="Orders" EntityType="ExampleModel.Order" />
          <AssociationSet 
                      Name="CustomerOrder" 
                      Association="ExampleModel.CustomerOrders">
            <End Role="Customer" EntitySet="Customers" />
            <End Role="Order" EntitySet="Orders" />
          </AssociationSet>
        </EntityContainer>
        <EntityType Name="Customer">
          <Key>
            <PropertyRef Name="CustomerId" />
          </Key>
          <Property Type="Int32" Name="CustomerId" Nullable="false" />
          <Property Type="String" Name="Name" Nullable="false" />
          <NavigationProperty 
                   Name="Orders" 
                   Relationship="ExampleModel.CustomerOrders" 
                   FromRole="Customer" ToRole="Order" />
        </EntityType>
        <EntityType Name="Order">
          <Key>
            <PropertyRef Name="OrderId" />
          </Key>
          <Property Type="Int32" Name="OrderId" Nullable="false" />
          <Property Type="Int32" Name="ProductId" Nullable="false" />
          <Property Type="Int32" Name="Quantity" Nullable="false" />
          <NavigationProperty 
                   Name="Customer" 
                   Relationship="ExampleModel.CustomerOrders" 
                   FromRole="Order" ToRole="Customer" />
          <Property Type="Int32" Name="CustomerId" Nullable="false" />
        </EntityType>
        <Association Name="CustomerOrders">
          <End Type="ExampleModel.Customer" 
               Role="Customer" Multiplicity="1" />
          <End Type="ExampleModel.Order" 
               Role="Order" Multiplicity="*" />
          <ReferentialConstraint>
            <Principal Role="Customer">
              <PropertyRef Name="CustomerId" />
            </Principal>
            <Dependent Role="Order">
              <PropertyRef Name="CustomerId" />
            </Dependent>
          </ReferentialConstraint>
        </Association>
      </Schema>

See Also

Concepts

Entity Framework Overview
CSDL Specification

Other Resources

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