Schema 元素 (SSDL)

在 实体数据模型 (EDM) 中,Schema 元素是存储元数据规范中的根元素。Schema 元素包含使用存储模型名称和类型的实体和关联的声明及定义。存储元数据在存储架构定义语言 (SSDL) 中定义。

EntityTypeAssociation 元素是 Schema 元素的子元素。EntitySetAssociationSet 元素是 EntityContainer 元素的子元素。

EntityContainer 元素包含在 Schema 元素中,但它是单独的元素并在逻辑上是独立的。在映射规范中,概念性架构中的 EntityContainer 将映射到存储元数据中的 EntityContainer,而无需引用架构命名空间。

下面的 SSDL 架构摘要演示 Schema 元素及它所包含的最重要的子元素。

<?xml version="1.0" encoding="utf-8"?>
<Schema Namespace="AdventureWorksHRTarget" Alias="Self"
          xmlns="https://schemas.microsoft.com/ado/2006/04/edm/ssdl">

  <EntityType Name="Department">
    <Key>
        <PropertyRef Name="DepartmentID">
    </Key>
    <Property Name="DepartmentID" Type="smallint"
                Nullable="false" StoreGeneratedPattern="Identity" />
    <Property Name="Name" Type="nvarchar" 
                              Nullable="false" MaxLength="50" />
    <Property Name="GroupName" Type="nvarchar"
                              Nullable="false" MaxLength="50" />
    <Property Name="ModifiedDate" Type="datetime" Nullable="false" />
  </EntityType>

<EntityType Name="Employee" >
    <Key>
        <PropertyRef Name="EmployeeID">
    </Key>
    <Property Name="EmployeeID" Type="int" Nullable="false"
                                  StoreGeneratedPattern="Identity" />
    <Property Name="NationalIDNumber" Type="nvarchar"
                              Nullable="false" MaxLength="15" />
    <Property Name="ContactID" Type="int" Nullable="false" />
    <Property Name="LoginID" Type="nvarchar" 
                             Nullable="false" MaxLength="256" />
    <Property Name="ManagerID" Type="int" />
    <Property Name="Title" Type="nvarchar" Nullable="false"
                                                   MaxLength="50" />
    <Property Name="BirthDate" Type="datetime" Nullable="false" />
    <Property Name="MaritalStatus" Type="nchar" Nullable="false"
                                  MaxLength="1" FixedLength="true" />
    <Property Name="Gender" Type="nchar" Nullable="false"
                              MaxLength="1" FixedLength="true" />
    <Property Name="HireDate" Type="datetime" Nullable="false" />
    <Property Name="SalariedFlag" Type="bit" Nullable="false" />
    <Property Name="VacationHours" Type="smallint" Nullable="false" />
    <Property Name="SickLeaveHours" Type="smallint" Nullable="false" />
    <Property Name="CurrentFlag" Type="bit" Nullable="false" />
    <Property Name="rowguid" Type="uniqueidentifier" Nullable="false" />
    <Property Name="ModifiedDate" Type="datetime" Nullable="false" />
  </EntityType>

<EntityContainer Name="HumanResources">
    <EntitySet Name="Department" EntityType="Self.Department" />
    <EntitySet Name="Employee" EntityType="Self.Employee" />
    <AssociationSet Name="Employee_EmployeeManagerID"
                  Association="Self.Employee_EmployeeManagerID">
      <End Role="Employee" EntitySet="Employee" />
      <End Role="Employee" EntitySet="Employee" />
    </AssociationSet>
  </EntityContainer>

</Schema>

下列主题介绍了 Schema 类型的 Namespace 属性和 Schema 元素的子元素(如 EntityTypeAssociation 等)以及其功能:

Namespace 属性 (SSDL)

EntityType 元素 (SSDL)

Association 元素 (SSDL)

其中的每个类型在 SSDL 架构中都有子元素。

另请参见

概念

EntityContainer 元素 (SSDL)
实现实体 (EDM)
实现关联 (EDM)

其他资源

EDM 规范