Поделиться через


ModificationFunctionMapping (EntityTypeMapping)

In the Entity Data Model (EDM), the ModificationFunctionMapping element, when it is a child element of an EntityTypeMapping element, specifies functions in the storage schema that handle change processing for an EntityType. The ModificationFunctionMapping element contains the DeleteFunction, InsertFunction, and UpdateFunction elements. Each of these function elements include a FunctionName element that maps to a stored procedure in the storage model.

The functions in a ModificationFunctionMapping element handle changes to an EntityType. In these instances, the ModificationFunctionMapping element is contained by the EntityTypeMapping element that is, in turn, contained by the EntitySetMapping element. In this case, associations are handled as part of operations on entities being created, modified, or deleted.

Note

The functions in a ModificationFunctionMapping element can also map to stored procedures that create or delete instances of an association between existing entities. In these instances, the ModificationFunctionMapping element is contained by an AssociationSetMapping element. For more information, see Mapping Association Sets to Stored Procedures (Entity Framework) and ModificationFunctionMapping (AssociationSetMapping).

Example

The following example shows how the ModificationFunctionMapping element maps function elements to stored procedures that handle changes for an EntityType. In this example, the ModificationFunctionMapping element maps functions that modify the SalesOrderDetail entity identified by the syntax, TypeName="AdventureWorksModel.SalesOrderDetail".

To use this mapping, all three update functions—insert, update, and delete—on SalesOrderDetail entities must map to stored procedures. Each of the three functions uses the following elements to complete this mapping:

  • The FunctionName element in each function element identifies each corresponding stored procedure in the storage schema by using the following syntax, FunctionName="AdventureWorksModel.Store.CreateSalesOrderDetail".

  • The ScalarProperty elements in each function element map properties of the target entity to corresponding parameters in the stored procedure.

  • The AssociationEnd elements in each Function element specify the details of updates to associations as required by the data model and corresponding foreign key relationships in the storage model. The AssociationEnd element within the EntityTypeMapping allows you to treat a relationship as a reference, or foreign key, specific to the entity. For more information, see Stored Procedure Support (Entity Framework).

The following example shows the full declaration of the ModificationFunctionMapping element. This schema can be generated by the Entity Framework design tools. For more information, see Walkthrough: Mapping an Entity to Stored Procedures.

<ModificationFunctionMapping >
  <InsertFunction
       FunctionName="AdventureWorksModel.Store.CreateSalesOrderDetail">
        <ScalarProperty Name="CarrierTrackingNumber"
              ParameterName="CarrierTrackingNumber" Version="Current"/>
        <ScalarProperty Name="OrderQty" ParameterName="OrderQty"
              Version="Current"/>
        <ScalarProperty Name="ProductID" ParameterName="ProductID"
              Version="Current"/>
        <ScalarProperty Name="SpecialOfferID"
              ParameterName="SpecialOfferID" Version="Current"/>
        <ScalarProperty Name="UnitPrice" ParameterName="UnitPrice"
              Version="Current"/>
        <ScalarProperty Name="UnitPriceDiscount"
              ParameterName="UnitPriceDiscount" Version="Current"/>
        <ScalarProperty Name="rowguid" ParameterName="rowguid" Version="Current"/>
        <ScalarProperty Name="ModifiedDate"
              ParameterName="ModifiedDate" Version="Current"/>
    <AssociationEnd
      AssociationSet="FK_SalesOrderDetail_SalesOrderHeader_SalesOrderID"
     From="SalesOrderDetail" To="SalesOrderHeader">
        <ScalarProperty Name="SalesOrderID"
           ParameterName="SalesOrderID" />
    </AssociationEnd>
    <ResultBinding ColumnName="SalesOrderDetailID"
       Name="SalesOrderDetailID" />
    <ResultBinding ColumnName="LineTotal" Name="LineTotal" />
  </InsertFunction>

  <UpdateFunction
     FunctionName="AdventureWorksModel.Store.UpdateSalesOrderDetail" >
        <ScalarProperty Name="OrderQty" ParameterName="OrderQty"  Version="Current"/>
        <ScalarProperty Name="SalesOrderDetailID"
           ParameterName="SalesOrderDetailID" Version="Current"/>
      <AssociationEnd
         AssociationSet="FK_SalesOrderDetail_SalesOrderHeader_SalesOrderID"
    From="SalesOrderDetail" To="SalesOrderHeader">
        <ScalarProperty Name="SalesOrderID"
          ParameterName="SalesOrderID" Version="Current" />
       </AssociationEnd>
  </UpdateFunction>

  <DeleteFunction
      FunctionName="AdventureWorksModel.Store.DeleteSalesOrderDetail" >
        <ScalarProperty Name="SalesOrderDetailID"
          ParameterName="SalesOrderDetailID" Version="Original"/>
    <AssociationEnd
      AssociationSet="FK_SalesOrderDetail_SalesOrderHeader_SalesOrderID"
         From="SalesOrderDetail" To="SalesOrderHeader">
          <ScalarProperty Name="SalesOrderID"
            ParameterName="SalesOrderID" />
    </AssociationEnd>
  </DeleteFunction>
</ModificationFunctionMapping>

See Also

Tasks

How to: Define a Model with a Stored Procedure (Entity Framework)

Concepts

ModificationFunctionMapping (AssociationSetMapping)
Stored Procedure Support (Entity Framework)

Other Resources

Walkthrough: Mapping an Entity to Stored Procedures