InsertFunction (EntityTypeMapping)

As a child element of an EntityTypeMapping element in the Entity Data Model (EDM), the InsertFunction element in a ModificationFunctionMapping element identifies the stored procedure that creates a new entity.

To create this new entity, the InsertFunction element maps the properties of an entity in the storage schema to the parameters of a stored procedure in the database. The stored procedure creates the new instance of the entity in storage.

Example

In the following example, the InsertFunction element maps a stored procedure that creates new instances of the SalesOrderDetail entity in the Adventureworks sales model. Each ScalarProperty child element in the InsertFunction element maps a property of the SalesOrderDetail entity to a parameter in the stored procedure. To map these entities, the ScalarProperty child element uses these attributes:

  • The Name attribute identifies the property of the SalesOrderDetail entity to be mapped.

  • The ParameterName attribute identifies the stored-procedure parameter to which the property of SalesOrderDetail entity maps.

  • The Version attribute specifies data as either original data read from the database, or current data that has possibly been changed by client code.

In addition to the ScalarProperty child element, the InsertFunction element includes an AssociationEnd element that maps associations that the entity being created may instantiate. For more information, see AssociationEnd (EntityTypeMapping).

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

See Also

Tasks

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

Concepts

Stored Procedure Support (Entity Framework)
ModificationFunctionMapping (AssociationSetMapping)
DeleteFunction (EntityTypeMapping)
UpdateFunction (EntityTypeMapping)