Udostępnij za pośrednictwem


Schema Element (SSDL)

The Schema element in store schema definition language (SSDL) is the root element of a storage model definition. It contains definitions for the objects, functions, and containers that make up a storage model.

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

The Schema element uses the Namespace attribute to define the namespace for the entity type and association objects in a storage model. Within a namespace, no two objects can have the same name.

A storage model namespace is different from the XML namespace of the Schema element. A storage model namespace (as defined by the Namespace attribute) is a logical container for entity 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/ssdl (where YYYY and MM represent a year and month respectively) are reserved for SSDL. 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 storage 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 ExampleModel.Store namespace, then the fully qualified name of the EntityType is ExampleModel.Store.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 CSDL Schema element.

Alias

No

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

Provider

Yes

The data provider. For more information, see Entity Framework Data Providers.

ProviderManifestToken

Yes

A token that indicates to the provider which provider manifest to return. No format for the token is defined. Values for the token are defined by the provider. For information about SQL Server provider manifest tokens, see SqlClient for the Entity Framework.

Example

The following example shows a Schema element that contains an EntityContainer element, two EntityType elements, and one Association element.

<Schema Namespace="ExampleModel.Store" 
      Alias="Self" Provider="System.Data.SqlClient" 
      ProviderManifestToken="2008" 
      xmlns="https://schemas.microsoft.com/ado/2009/02/edm/ssdl">
  <EntityContainer Name="ExampleModelStoreContainer">
    <EntitySet Name="Customers" 
               EntityType="ExampleModel.Store.Customers" 
               Schema="dbo" />
    <EntitySet Name="Orders" 
               EntityType="ExampleModel.Store.Orders" 
               Schema="dbo" />
    <AssociationSet Name="FK_CustomerOrders" 
                    Association="ExampleModel.Store.FK_CustomerOrders">
      <End Role="Customers" EntitySet="Customers" />
      <End Role="Orders" EntitySet="Orders" />
    </AssociationSet>
  </EntityContainer>
  <EntityType Name="Customers">
    <Documentation>
      <Summary>Summary here.</Summary>
      <LongDescription>Long description here.</LongDescription>
    </Documentation>
    <Key>
      <PropertyRef Name="CustomerId" />
    </Key>
    <Property Name="CustomerId" Type="int" Nullable="false" />
    <Property Name="Name" Type="nvarchar(max)" Nullable="false" />
  </EntityType>
  <EntityType Name="Orders" xmlns:c="http://CustomNamespace">
    <Key>
      <PropertyRef Name="OrderId" />
    </Key>
    <Property Name="OrderId" Type="int" Nullable="false" 
              c:CustomAttribute="someValue"/>
    <Property Name="ProductId" Type="int" Nullable="false" />
    <Property Name="Quantity" Type="int" Nullable="false" />
    <Property Name="CustomerId" Type="int" Nullable="false" />
    <c:CustomElement>
      Custom data here.
    </c:CustomElement>
  </EntityType>
  <Association Name="FK_CustomerOrders">
    <End Role="Customers" 
         Type="ExampleModel.Store.Customers" Multiplicity="1">
      <OnDelete Action="Cascade" />
    </End>
    <End Role="Orders" 
         Type="ExampleModel.Store.Orders" Multiplicity="*" />
    <ReferentialConstraint>
      <Principal Role="Customers">
        <PropertyRef Name="CustomerId" />
      </Principal>
      <Dependent Role="Orders">
        <PropertyRef Name="CustomerId" />
      </Dependent>
    </ReferentialConstraint>
  </Association>
  <Function Name="UpdateOrderQuantity" 
            Aggregate="false" 
            BuiltIn="false" 
            NiladicFunction="false" 
            IsComposable="false" 
            ParameterTypeSemantics="AllowImplicitConversion" 
            Schema="dbo">
    <Parameter Name="orderId" Type="int" Mode="In" />
    <Parameter Name="newQuantity" Type="int" Mode="In" />
  </Function>
  <Function Name="UpdateProductInOrder" IsComposable="false">
    <CommandText>
      UPDATE Orders
      SET ProductId = @productId
      WHERE OrderId = @orderId;
    </CommandText>
    <Parameter Name="productId"
               Mode="In"
               Type="int"/>
    <Parameter Name="orderId"
               Mode="In"
               Type="int"/>
  </Function>
</Schema>

See Also

Concepts

Entity Framework Overview
SSDL Specification

Other Resources

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