存储元数据架构 (SSDL)

存储元数据架构是对为在 实体数据模型 (EDM) 上生成的应用程序持久存储数据的数据库的形式说明。此架构中声明的实体和关联是将概念性架构中的实体和关联映射到存储模型中的相应实体的基础。

存储架构定义语言 (SSDL) 中声明的实体非常类似于概念性架构定义语言 (CSDL) 中声明的实体。两者的区别主要在于 SSDL 声明中使用的数据类型。SSDL 文件中声明的属性的数据类型是存储模型中的类型。CSDL 文件中的数据类型是由 EDM 定义的简单类型。这些类型之间的映射是 EDM 的功能之一。有关 CSDL 和 SSDL 中使用的数据类型的更多信息,请参见简单类型 (EDM)

元数据和映射

SSDL 架构中声明的命名空间名称和实体容器是映射规范用来将存储中的表与 CSDL 架构中的实体联系起来的元数据。

Note注意

SSDL 命名空间不同于 XML 命名空间。SSDL 命名空间用于完全限定实体类型名称和关联名称。例如,当映射规范语言 (MSL) 引用实体类型时,必须提供完全限定名称。SSDL 位于 XML 命名空间 https://schemas.microsoft.com/ado/2006/04/edm/ssdl 中。这两种类型的命名空间彼此独立,截然不同,不应当混淆。

Human Resources SSDL 架构中的下列代码行为此架构包含的元数据声明了一个命名空间。命名空间名称将由映射规范语言 (MSL) 使用。

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

SSDL 架构包括一个也将由映射规范使用的 EntityContainer 元素。下面的 SSDL 片段说明了实体容器的声明。

  <EntityContainer Name="HumanResources">
    <EntitySet Name="Department" EntityType="Self.Department" />
    <EntitySet Name="Employee" EntityType="Self.Employee" />
    <EntitySet Name="EmployeeAddress" EntityType="Self.EmployeeAddress" />
    <EntitySet Name="EmployeeDepartmentHistory"
                      EntityType="Self.EmployeeDepartmentHistory" />
    <EntitySet Name="EmployeePayHistory"
                             EntityType="Self.EmployeePayHistory" />
    <EntitySet Name="JobCandidate" EntityType="Self.JobCandidate" />
    <EntitySet Name="Shift" EntityType="Self.Shift" />
    <AssociationSet Name="FK_Employee_Employee_ManagerID"
                  Association="Self.FK_Employee_Employee_ManagerID">
      <End Role="Employee" EntitySet="Employee" />
      <End Role="Employee63" EntitySet="Employee" />
    </AssociationSet>
    <AssociationSet Name="FK_JobCandidate_Employee_EmployeeID" 
            Association="Self.FK_JobCandidate_Employee_EmployeeID">
      <End Role="Employee" EntitySet="Employee" />
      <End Role="JobCandidate" EntitySet="JobCandidate" />
    </AssociationSet>
  </EntityContainer>

SSDL 元数据中的实体和关联指定了存储模型中的表和列。CSDL 架构中和存储中的实体之间的映射需要使用此元数据。

概念性架构和存储架构中的 EntityContainer 元素独立于 Schema 元素,即使它们由 Schema 元素包含。MSL 中的 EntityContainerMapping 元素将 SSDL 文件的 EntityContainer 映射到 CSDL 文件中的 EntityContainer,并且无需引用各个架构中声明的命名空间名称:edm:CdmEntityContainer="HumanResources"``edm:StorageEntityContainer="HumanResources"

下面的 MSL 头演示概念性架构中的 HumanResources 实体容器(此处称为 CdmEntityContainer)和存储元数据(称为 StorageEntityContainer)之间的映射。

<?xml version="1.0" encoding="utf-8"?>
<Mapping edm:Space="C-S" 
    xmlns="urn:schemas-microsoft-com:windows:storage:mapping:CS">
  < EntityContainerMapping
                  CdmEntityContainer="HumanResources"
                  StorageEntityContainer="HumanResources">

下列主题对本主题的示例中使用的 SSDL 语法进行了更为全面的描述:

Schema 元素 (SSDL)

Namespace 属性 (SSDL)

EntityType 元素 (SSDL)

Association 元素 (SSDL)

EntityContainer 元素 (SSDL)

另请参见

概念

实体数据模型类型
AdventureWorks 完整模型 (EDM)