共用方式為


Schema 項目 (SSDL)

存放結構定義語言 (SSDL) 中的 Schema 項目是儲存模型定義的根項目。 其中包含組成儲存模型的物件、函式和容器等定義。

Schema 項目可以包含零個或多個下列子項目:

Schema 項目會使用 Namespace 屬性定義儲存模型中的實體類型和關聯物件的命名空間。 在命名空間中,兩個物件不能有相同的名稱。

儲存模型命名空間與 Schema 項目的 XML 命名空間不同。 儲存模型命名空間 (由 Namespace 屬性定義) 是實體類型和關聯型別的邏輯容器。 Schema 項目的 XML 命名空間 (由 xmlns 屬性表示) 是子項目和 Schema 項目屬性的預設命名空間。 XML 命名空間的格式 https://schemas.microsoft.com/ado/YYYY/MM/edm/ssdl (其中的 YYYY 和 MM 分別表示年和月) 是保留給 SSDL 之用。 自訂項目和屬性不能出現在擁有此格式的命名空間中。

適用屬性

以下資料表描述的屬性可套用至 Schema 項目。

屬性名稱 必要

Namespace

儲存模型的命名空間。 Namespace 屬性的值是用來構成型別的完整限定名稱。 例如,假設 ExampleModel.Store 命名空間中有一個名為 CustomerEntityType,則 EntityType 的完整限定名稱是 ExampleModel.Store.Customer。

以下字串不能用來作為 Namespace 屬性的值:SystemTransientEdmNamespace 屬性的值與 CSDL Schema 項目中的 Namespace 屬性值,兩者不能相同。

Alias

用來取代命名空間名稱的識別項。 例如,假設 ExampleModel.Store 命名空間中有一個名為 CustomerEntityType,且 Alias 屬性的值是 StorageModel,則您可以使用 StorageModel.Customer 做為 EntityType. 的完整限定名稱。

Provider

資料提供者。 如需詳細資訊,請參閱 Entity Framework 資料提供者

ProviderManifestToken

向提供者表示要傳回哪個提供者資訊清單的語彙基元。 未定義此語彙基元的格式。 語彙基元的值是由提供者定義。 如需 SQL Server 提供者資訊清單語彙基元的詳細資訊,請參閱 適用於 Entity Framework 的 .NET Framework Data Provider for SQL Server (SqlClient)

範例

下列範例顯示一個 Schema 項目,其中包含一個 EntityContainer 項目、兩個 EntityType 項目和一個 Association 項目。

<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>

另請參閱

概念

Entity Framework 概觀
SSDL 規格

其他資源

CSDL、SSDL 和 MSL 規格
ADO.NET Entity Data Model Tools