次の方法で共有


Schema 要素 (SSDL)

ストア スキーマ定義言語 (SSDL) の Schema 要素は、ストレージ モデル定義のルート要素です。 ストレージ モデルを構成するオブジェクト、関数、およびコンテナーの定義を格納します。

Schema 要素には、0 個以上の次の子要素を含めることができます。

Schema 要素は、Namespace 属性を使用してストレージ モデルのエンティティ型とアソシエーション オブジェクトの名前空間を定義します。 1 つの名前空間内で 2 つのオブジェクトが同じ名前を持つことはできません。

ストレージ モデル名前空間は、Schema 要素の XML 名前空間とは異なります。 ストレージ モデル名前空間 (Namespace 属性で定義) は、エンティティ型とアソシエーション型の論理コンテナーです。 Schema 要素の XML 名前空間 (xmlns 属性で示される) は、Schema 要素の子要素と属性の既定の名前空間です。 フォーム https://schemas.microsoft.com/ado/YYYY/MM/edm/ssdl (YYYY と MM は、それぞれ年と月を表します) の XML 名前空間は、SSDL 用に予約されています。 カスタム要素と属性は、このフォームがある名前空間に存在することはできません。

適用可能な属性

The table below describes the attributes can be applied to the Schema element.

属性名 必須 Value

Namespace

有効

ストレージ モデルの名前空間。 Namespace 属性の値は、型の完全修飾名を形成するために使用されます。 たとえば、Customer という名前の EntityType が ExampleModel.Store 名前空間にある場合、この EntityType の完全修飾名は ExampleModel.Store.Customer です。

Namespace 属性の値として、文字列 SystemTransient、または Edm を使用することはできません。 The value for the Namespace attribute cannot be the same as the value for the Namespace attribute in the CSDL Schema element.

Alias

いいえ

名前空間の名前の代わりに使用される識別子。 たとえば、Customer という名前の EntityType が、ExampleModel.Store 名前空間にあり、Alias 属性の値が StorageModel である場合、StorageModel.Customer を EntityType の完全修飾名として使用できます。

Provider

有効

データ プロバイダー。 詳細については、「Entity Framework データ プロバイダー」を参照してください。

ProviderManifestToken

有効

返すプロバイダー マニフェストをプロバイダーに示すトークン。 トークンの形式は定義されていません。 トークンの値は、プロバイダーで定義されています。 SQL Server プロバイダー マニフェスト トークンの詳細については、「.NET Framework Data Provider for SQL Server (SqlClient) (Entity Framework 用)」を参照してください。

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>

参照

概念

エンティティ フレームワークの概要
SSDL 仕様

その他のリソース

CSDL、SSDL、および MSL 仕様
ADO.NET Entity Data Model Tools