Share via


ModificationFunctionMapping (AssociationSetMapping)

Entity Data Model (EDM) の AssociationSetMapping 要素の子要素として、ModificationFunctionMapping 要素は、エンティティ間の Association のインスタンスを挿入または削除するストアド プロシージャを指定します。ストレージ モデルのリンク テーブルでサポートされる多対多のアソシエーションをマップする場合に、AssociationSetMapping 要素内の ModificationFunctionMapping 要素を使用します。

AssociationSetMappping 関数では、ModificationFunctionMapping 要素には、エンティティ間のアソシエーションを作成するストアド プロシージャを示す InsertFunction 要素が含まれます。ModificationFunctionMapping 要素には、エンティティ間のアソシエーションを削除するストアド プロシージャを示す DeleteFunction 要素も含まれます。アソシエーション内でエンティティを定義するには、InsertFunction 要素と DeleteFunction 要素の両方に EndProperty 子要素を指定します。

[!メモ]

ModificationFunctionMapping 要素は、EntityType 要素のインスタンスを挿入、更新、または削除するストアド プロシージャをマップすることもできます。このインスタンスでは、ModificationFunctionMapping 要素は、EntityTypeMapping 要素の子要素であり、さらに、後者の要素は EntitySetMapping 要素に含まれます。詳細については、「ModificationFunctionMapping (EntityTypeMapping)」および「ストアド プロシージャのサポート (Entity Framework)」を参照してください。

この例では、ModificationFunctionMapping 要素は自身の InsertFunction 要素と DeleteFunction 要素を使用して、Contact エンティティと Address エンティティの間のアソシエーションを作成または削除するストアド プロシージャを指定します。Contact エンティティと Address エンティティを指定するために、InsertFunction 要素と DeleteFunction 要素は EndProperty 要素を使用しています。これらの EndProperty 要素は、それぞれの ScalarProperty 子要素を使用して、Association の各 End でエンティティのキー値のパラメータ バインドを示します。ScalarProperty 子要素は、ストアド プロシージャの対応するパラメータも指定します。

[!メモ]

AssociationSet のストアド プロシージャ マッピングで宣言される EndProperty のバインドは、EntitySet 関数マッピングで宣言される AssociationEnd 要素に似ています。ただし、EndProperty 要素の場合は、親の AssociationSet 要素が必要なコンテキストを提供します。

次の例では、ModificationFunctionMapping 要素を持つ完全な AssociationSetMapping 要素を示します。

  <AssociationSetMapping Name="Contact_Address"
                TypeName="ContactInformationModel.Contact_Address"
                StoreEntitySet="Contact_Address">
    <EndProperty Name="Address">
      <ScalarProperty Name="AddressID" ColumnName="AddressID" />
    </EndProperty>
    <EndProperty Name="Contact">
      <ScalarProperty Name="ContactID" ColumnName="ContactID" />
    </EndProperty>
    <ModificationFunctionMapping>
      <DeleteFunction
        FunctionName="ContactInformationModel.Store.DeleteAddress">
        <EndProperty Name="Address">
          <ScalarProperty Name="AddressID" ParameterName="AddressID"/>
        </EndProperty>
        <EndProperty Name="Contact">
          <ScalarProperty Name="ContactID" ParameterName="ContactID"/>
        </EndProperty>
      </DeleteFunction>
      <InsertFunction
        FunctionName="ContactInformationModel.Store.SetAddress">
        <EndProperty Name="Address">
          <ScalarProperty Name="AddressID" ParameterName="AddressID"/>
        </EndProperty>
        <EndProperty Name="Contact">
          <ScalarProperty Name="ContactID" ParameterName="ContactID"/>
        </EndProperty>
      </InsertFunction>
    </ModificationFunctionMapping>

参照

処理手順

ストアド プロシージャを使用してモデルを定義する方法 (Entity Framework)

概念

ストアド プロシージャのサポート (Entity Framework)
InsertFunction (AssociationSetMapping)
DeleteFunction (AssociationSetMapping)
EndProperty (AssociationSet ModificationFunctionMapping)