次の方法で共有


End 要素 (SSDL)

ストア スキーマ定義言語 (SSDL) の End 要素は、基になるデータベースで外部キー制約の一方の End でテーブルと行数を指定します。End 要素は、Association 要素または AssociationSet 要素の子にすることができます。それぞれの場合において、使用可能な子要素と該当する属性は異なります。

Association 要素の子としての End 要素

Association 要素の子である End 要素は、Type 属性と Multiplicity 属性をそれぞれ使用して、外部キー制約の End でテーブルと行数を指定します。外部キー制約の End は、SSDL アソシエーションの一部として定義されます。SSDL アソシエーションには End が 2 つ必要です。

End 要素には、ここに示した順序で次の子要素を含めることができます。

適用可能な属性

End 要素が Association 要素の子である場合に適用できる属性を次の表に示します。

属性名

必須

Type

はい

外部キー制約の End にある SSDL エンティティ セットの完全修飾名。

Role

いいえ

対応する ReferentialConstraint 要素Principal または Dependent 要素の Role 属性の値 (使用する場合)。

Multiplicity

有効

外部キー制約の End に存在できる行数に応じて、1、0..1、または *。

  • 1 は、外部キー制約の End に 1 行存在することを示します。

  • 0..1 は、外部キー制約の End に 0 行または 1 行存在することを示します。

  • * は、外部キー制約の End に 0 行以上存在することを示します。

注意

End 要素には、任意の数の annotation 属性 (カスタム XML 属性) を適用できます。ただし、カスタム属性は CSDL 用に予約されたどの XML 名前空間にも属さない場合があります。カスタム属性の完全修飾名は一意である必要があります。

次の例では、FK_CustomerOrders 外部キー制約を定義する Association 要素を示します。各 End 要素に指定されている Multiplicity 値は、Orders テーブルの複数の行を Customers テーブルの 1 行に関連付けることができるが、Orders テーブルの 1 行に関連付けることができるのは Customers テーブルの 1 行のみであることを示します。さらに、OnDelete 要素は、Customers テーブルの行が削除される場合、Customers テーブルの特定の行を参照している Orders テーブルのすべての行も削除されることを示します。

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

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

AssociationSet 要素の子としての End 要素

AssociationSet 要素の子である End 要素は、基になるデータベースで外部キー制約の一方の End でテーブルを指定します。

End 要素には、ここに示した順序で次の子要素を含めることができます。

適用可能な属性

End 要素が AssociationSet 要素の子である場合に適用できる属性を次の表に示します。

属性名

必須

EntitySet

はい

外部キー制約の End にある SSDL エンティティ セットの名前。

Role

いいえ

対応する Association 要素の 1 つの End 要素で指定されているいずれかの Role 属性の値。

注意

End 要素には、任意の数の annotation 属性 (カスタム XML 属性) を適用できます。ただし、カスタム属性は CSDL 用に予約されたどの XML 名前空間にも属さない場合があります。カスタム属性の完全修飾名は一意である必要があります。

次の例は、AssociationSet 要素と 2 つの End 要素を持つ EntityContainer 要素を示します。

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

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

関連項目

概念

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

SSDL 仕様

その他の技術情報

CSDL、SSDL、および MSL 仕様

ADO.NET Entity Data Model ツール