AdventureWorks 销售存储架构 (EDM)

在 实体数据模型 (EDM) 中,存储元数据是使用存储架构定义语言 (SSDL) 定义的。在本示例中,SSDL 架构表示 Adventure Works 示例数据库中的表和键的数据。

SSDL 架构

下面的示例包含 Adventure Works 数据库中的五个表的元数据。XML 语法用于定义存储模型的结构。实体集表示表。实体类型表示行。属性表示行中的列。关联表示外键关系。关联集从逻辑上定义关联的作用域。

此架构用于将前一主题 AdventureWorks 销售概念架构 (EDM) 中的模型映射到存储。

下面的示例显示了完整的 SSDL 架构。

<?xml version="1.0" encoding="utf-8"?>
<Schema Namespace="AdvWrksSalesModel.Store" Alias="Self"
    Provider="System.Data.SqlClient"
    ProviderManifestToken="2005"
    xmlns="https://schemas.microsoft.com/ado/2006/04/edm/ssdl">
  <EntityContainer Name="Person">
    <EntitySet Name="Address" EntityType="AdvWrksSalesModel.Store.Address" />
    <EntitySet Name="Contact" EntityType="AdvWrksSalesModel.Store.Contact" />
    <EntitySet Name="Product" EntityType="AdvWrksSalesModel.Store.Product" Schema="Production" />
    <EntitySet Name="SalesOrderDetail" EntityType="AdvWrksSalesModel.Store.SalesOrderDetail" Schema="Sales" />
    <EntitySet Name="SalesOrderHeader" EntityType="AdvWrksSalesModel.Store.SalesOrderHeader" Schema="Sales" />
    <AssociationSet Name="FK_SalesOrderDetail_SalesOrderHeader_SalesOrderID" Association="AdvWrksSalesModel.Store.FK_SalesOrderDetail_SalesOrderHeader_SalesOrderID">
      <End Role="SalesOrderHeader" EntitySet="SalesOrderHeader" />
      <End Role="SalesOrderDetail" EntitySet="SalesOrderDetail" />
    </AssociationSet>
    <AssociationSet Name="FK_SalesOrderHeader_Address_BillToAddressID" Association="AdvWrksSalesModel.Store.FK_SalesOrderHeader_Address_BillToAddressID">
      <End Role="Address" EntitySet="Address" />
      <End Role="SalesOrderHeader" EntitySet="SalesOrderHeader" />
    </AssociationSet>
    <AssociationSet Name="FK_SalesOrderHeader_Address_ShipToAddressID" Association="AdvWrksSalesModel.Store.FK_SalesOrderHeader_Address_ShipToAddressID">
      <End Role="Address" EntitySet="Address" />
      <End Role="SalesOrderHeader" EntitySet="SalesOrderHeader" />
    </AssociationSet>
    <AssociationSet Name="FK_SalesOrderHeader_Contact_ContactID" Association="AdvWrksSalesModel.Store.FK_SalesOrderHeader_Contact_ContactID">
      <End Role="Contact" EntitySet="Contact" />
      <End Role="SalesOrderHeader" EntitySet="SalesOrderHeader" />
    </AssociationSet>
  </EntityContainer>
  <EntityType Name="Address">
    <Key>
      <PropertyRef Name="AddressID" />
    </Key>
    <Property Name="AddressID" Type="int" Nullable="false" StoreGeneratedPattern="Identity" />
    <Property Name="AddressLine1" Type="nvarchar" Nullable="false" MaxLength="60" />
    <Property Name="AddressLine2" Type="nvarchar" MaxLength="60" />
    <Property Name="City" Type="nvarchar" Nullable="false" MaxLength="30" />
    <Property Name="StateProvinceID" Type="int" Nullable="false" />
    <Property Name="PostalCode" Type="nvarchar" Nullable="false" MaxLength="15" />
    <Property Name="rowguid" Type="uniqueidentifier" Nullable="false" />
    <Property Name="ModifiedDate" Type="datetime" Nullable="false" />
  </EntityType>
  <EntityType Name="Contact">
    <Key>
      <PropertyRef Name="ContactID" />
    </Key>
    <Property Name="ContactID" Type="int" Nullable="false" StoreGeneratedPattern="Identity" />
    <Property Name="NameStyle" Type="bit" Nullable="false" />
    <Property Name="Title" Type="nvarchar" MaxLength="8" />
    <Property Name="FirstName" Type="nvarchar" Nullable="false" MaxLength="50" />
    <Property Name="MiddleName" Type="nvarchar" MaxLength="50" />
    <Property Name="LastName" Type="nvarchar" Nullable="false" MaxLength="50" />
    <Property Name="Suffix" Type="nvarchar" MaxLength="10" />
    <Property Name="EmailAddress" Type="nvarchar" MaxLength="50" />
    <Property Name="EmailPromotion" Type="int" Nullable="false" />
    <Property Name="Phone" Type="nvarchar" MaxLength="25" />
    <Property Name="PasswordHash" Type="varchar" Nullable="false" MaxLength="128" />
    <Property Name="PasswordSalt" Type="varchar" Nullable="false" MaxLength="10" />
    <Property Name="AdditionalContactInfo" Type="xml" />
    <Property Name="rowguid" Type="uniqueidentifier" Nullable="false" />
    <Property Name="ModifiedDate" Type="datetime" Nullable="false" />
  </EntityType>
  <EntityType Name="Product">
    <Key>
      <PropertyRef Name="ProductID" />
    </Key>
    <Property Name="ProductID" Type="int" Nullable="false" StoreGeneratedPattern="Identity" />
    <Property Name="Name" Type="nvarchar" Nullable="false" MaxLength="50" />
    <Property Name="ProductNumber" Type="nvarchar" Nullable="false" MaxLength="25" />
    <Property Name="MakeFlag" Type="bit" Nullable="false" />
    <Property Name="FinishedGoodsFlag" Type="bit" Nullable="false" />
    <Property Name="Color" Type="nvarchar" MaxLength="15" />
    <Property Name="SafetyStockLevel" Type="smallint" Nullable="false" />
    <Property Name="ReorderPoint" Type="smallint" Nullable="false" />
    <Property Name="StandardCost" Type="money" Nullable="false" />
    <Property Name="ListPrice" Type="money" Nullable="false" />
    <Property Name="Size" Type="nvarchar" MaxLength="5" />
    <Property Name="SizeUnitMeasureCode" Type="nchar" MaxLength="3" />
    <Property Name="WeightUnitMeasureCode" Type="nchar" MaxLength="3" />
    <Property Name="Weight" Type="decimal" Precision="8" Scale="2" />
    <Property Name="DaysToManufacture" Type="int" Nullable="false" />
    <Property Name="ProductLine" Type="nchar" MaxLength="2" />
    <Property Name="Class" Type="nchar" MaxLength="2" />
    <Property Name="Style" Type="nchar" MaxLength="2" />
    <Property Name="ProductSubcategoryID" Type="int" />
    <Property Name="ProductModelID" Type="int" />
    <Property Name="SellStartDate" Type="datetime" Nullable="false" />
    <Property Name="SellEndDate" Type="datetime" />
    <Property Name="DiscontinuedDate" Type="datetime" />
    <Property Name="rowguid" Type="uniqueidentifier" Nullable="false" />
    <Property Name="ModifiedDate" Type="datetime" Nullable="false" />
  </EntityType>
  <EntityType Name="SalesOrderDetail">
    <Key>
      <PropertyRef Name="SalesOrderID" />
      <PropertyRef Name="SalesOrderDetailID" />
    </Key>
    <Property Name="SalesOrderID" Type="int" Nullable="false" />
    <Property Name="SalesOrderDetailID" Type="int" Nullable="false" StoreGeneratedPattern="Identity" />
    <Property Name="CarrierTrackingNumber" Type="nvarchar" MaxLength="25" />
    <Property Name="OrderQty" Type="smallint" Nullable="false" />
    <Property Name="ProductID" Type="int" Nullable="false" />
    <Property Name="SpecialOfferID" Type="int" Nullable="false" />
    <Property Name="UnitPrice" Type="money" Nullable="false" />
    <Property Name="UnitPriceDiscount" Type="money" Nullable="false" />
    <Property Name="LineTotal" Type="numeric" Nullable="false" Precision="38" Scale="6" StoreGeneratedPattern="Computed" />
    <Property Name="rowguid" Type="uniqueidentifier" Nullable="false" />
    <Property Name="ModifiedDate" Type="datetime" Nullable="false" />
  </EntityType>
  <EntityType Name="SalesOrderHeader">
    <Key>
      <PropertyRef Name="SalesOrderID" />
    </Key>
    <Property Name="SalesOrderID" Type="int" Nullable="false" StoreGeneratedPattern="Identity" />
    <Property Name="RevisionNumber" Type="tinyint" Nullable="false" />
    <Property Name="OrderDate" Type="datetime" Nullable="false" />
    <Property Name="DueDate" Type="datetime" Nullable="false" />
    <Property Name="ShipDate" Type="datetime" />
    <Property Name="Status" Type="tinyint" Nullable="false" />
    <Property Name="OnlineOrderFlag" Type="bit" Nullable="false" />
    <Property Name="SalesOrderNumber" Type="nvarchar" Nullable="false" MaxLength="25" StoreGeneratedPattern="Computed" />
    <Property Name="PurchaseOrderNumber" Type="nvarchar" MaxLength="25" />
    <Property Name="AccountNumber" Type="nvarchar" MaxLength="15" />
    <Property Name="CustomerID" Type="int" Nullable="false" />
    <Property Name="ContactID" Type="int" Nullable="false" />
    <Property Name="SalesPersonID" Type="int" />
    <Property Name="TerritoryID" Type="int" />
    <Property Name="BillToAddressID" Type="int" Nullable="false" />
    <Property Name="ShipToAddressID" Type="int" Nullable="false" />
    <Property Name="ShipMethodID" Type="int" Nullable="false" />
    <Property Name="CreditCardID" Type="int" />
    <Property Name="CreditCardApprovalCode" Type="varchar" MaxLength="15" />
    <Property Name="CurrencyRateID" Type="int" />
    <Property Name="SubTotal" Type="money" Nullable="false" />
    <Property Name="TaxAmt" Type="money" Nullable="false" />
    <Property Name="Freight" Type="money" Nullable="false" />
    <Property Name="TotalDue" Type="money" Nullable="false" StoreGeneratedPattern="Computed" />
    <Property Name="Comment" Type="nvarchar" MaxLength="128" />
    <Property Name="rowguid" Type="uniqueidentifier" Nullable="false" />
    <Property Name="ModifiedDate" Type="datetime" Nullable="false" />
  </EntityType>
  <Association Name="FK_SalesOrderDetail_SalesOrderHeader_SalesOrderID">
    <End Role="SalesOrderHeader" Type="AdvWrksSalesModel.Store.SalesOrderHeader" Multiplicity="1">
      <OnDelete Action="Cascade" />
    </End>
    <End Role="SalesOrderDetail" Type="AdvWrksSalesModel.Store.SalesOrderDetail" Multiplicity="*" />
    <ReferentialConstraint>
      <Principal Role="SalesOrderHeader">
        <PropertyRef Name="SalesOrderID" />
      </Principal>
      <Dependent Role="SalesOrderDetail">
        <PropertyRef Name="SalesOrderID" />
      </Dependent>
    </ReferentialConstraint>
  </Association>
  <Association Name="FK_SalesOrderHeader_Address_BillToAddressID">
    <End Role="Address" Type="AdvWrksSalesModel.Store.Address" Multiplicity="1" />
    <End Role="SalesOrderHeader" Type="AdvWrksSalesModel.Store.SalesOrderHeader" Multiplicity="*" />
    <ReferentialConstraint>
      <Principal Role="Address">
        <PropertyRef Name="AddressID" />
      </Principal>
      <Dependent Role="SalesOrderHeader">
        <PropertyRef Name="BillToAddressID" />
      </Dependent>
    </ReferentialConstraint>
  </Association>
  <Association Name="FK_SalesOrderHeader_Address_ShipToAddressID">
    <End Role="Address" Type="AdvWrksSalesModel.Store.Address" Multiplicity="1" />
    <End Role="SalesOrderHeader" Type="AdvWrksSalesModel.Store.SalesOrderHeader" Multiplicity="*" />
    <ReferentialConstraint>
      <Principal Role="Address">
        <PropertyRef Name="AddressID" />
      </Principal>
      <Dependent Role="SalesOrderHeader">
        <PropertyRef Name="ShipToAddressID" />
      </Dependent>
    </ReferentialConstraint>
  </Association>
  <Association Name="FK_SalesOrderHeader_Contact_ContactID">
    <End Role="Contact" Type="AdvWrksSalesModel.Store.Contact" Multiplicity="1" />
    <End Role="SalesOrderHeader" Type="AdvWrksSalesModel.Store.SalesOrderHeader" Multiplicity="*" />
    <ReferentialConstraint>
      <Principal Role="Contact">
        <PropertyRef Name="ContactID" />
      </Principal>
      <Dependent Role="SalesOrderHeader">
        <PropertyRef Name="ContactID" />
      </Dependent>
    </ReferentialConstraint>
  </Association>
</Schema>

另请参见

概念

AdventureWorks 销售概念架构 (EDM)
AdventureWorks 销售映射架构 (EDM)
AdventureWorks 销售连接 (EDM)