ModificationFunctionMapping Element (MSL)

The ModificationFunctionMapping element in mapping specification language (MSL) maps the insert, update, and delete functions of a conceptual model entity type to stored procedures in the underlying database. The ModificationFunctionMapping element can also map the insert and delete functions for many-to-many associations in the conceptual model to stored procedures in the underlying database. Stored procedures to which modification functions are mapped must be declared in the storage model. For more information, see Function Element (SSDL).

Note

If you do not map all three of the insert, update, or delete operations of a entity type to stored procedures, the unmapped operations will fail if executed at runtime and an UpdateException is thrown.

Note

If the modification functions for one entity in an inheritance hierarchy are mapped to stored procedures, then modification functions for all types in the hierarchy must be mapped to stored procedures.

The ModificationFunctionMapping element can be a child of the EntityTypeMapping element or the AssociationSetMapping element.

The ModificationFunctionMapping element can have the following child elements:

No attributes are applicable to the ModificationFunctionMapping element.

Example

The following example shows the entity set mapping for the People entity set in the School model. In addition to the column mapping for the Person entity type, the mapping of the insert, update, and delete functions of the Person type are shown. The functions that are mapped to are declared in the storage model.

<EntitySetMapping Name="People">
  <EntityTypeMapping TypeName="SchoolModel.Person">
    <MappingFragment StoreEntitySet="Person">
      <ScalarProperty Name="PersonID" ColumnName="PersonID" />
      <ScalarProperty Name="LastName" ColumnName="LastName" />
      <ScalarProperty Name="FirstName" ColumnName="FirstName" />
      <ScalarProperty Name="HireDate" ColumnName="HireDate" />
      <ScalarProperty Name="EnrollmentDate" 
                      ColumnName="EnrollmentDate" />
    </MappingFragment>
</EntityTypeMapping>
  <EntityTypeMapping TypeName="SchoolModel.Person">
    <ModificationFunctionMapping>
      <InsertFunction FunctionName="SchoolModel.Store.InsertPerson">
        <ScalarProperty Name="EnrollmentDate"
                        ParameterName="EnrollmentDate" />
        <ScalarProperty Name="HireDate" ParameterName="HireDate" />
        <ScalarProperty Name="FirstName" ParameterName="FirstName" />
        <ScalarProperty Name="LastName" ParameterName="LastName" />
        <ResultBinding Name="PersonID" ColumnName="NewPersonID" />
      </InsertFunction>
      <UpdateFunction FunctionName="SchoolModel.Store.UpdatePerson">
        <ScalarProperty Name="EnrollmentDate"
                        ParameterName="EnrollmentDate"
                        Version="Current" />
        <ScalarProperty Name="HireDate" ParameterName="HireDate"
                        Version="Current" />
        <ScalarProperty Name="FirstName" ParameterName="FirstName"
                        Version="Current" />
        <ScalarProperty Name="LastName" ParameterName="LastName"
                        Version="Current" />
        <ScalarProperty Name="PersonID" ParameterName="PersonID"
                        Version="Current" />
      </UpdateFunction>
      <DeleteFunction FunctionName="SchoolModel.Store.DeletePerson">
        <ScalarProperty Name="PersonID" ParameterName="PersonID" />
      </DeleteFunction>
    </ModificationFunctionMapping>
  </EntityTypeMapping>
</EntitySetMapping>

Example

The following example shows the association set mapping for the CourseInstructor association set in the School model. In addition to the column mapping for the CourseInstructor association, the mapping of the insert and delete functions of the CourseInstructor association are shown. The functions that are mapped to are declared in the storage model.

<AssociationSetMapping Name="CourseInstructor" 
                       TypeName="SchoolModel.CourseInstructor" 
                       StoreEntitySet="CourseInstructor">
  <EndProperty Name="Person">
    <ScalarProperty Name="PersonID" ColumnName="PersonID" />
  </EndProperty>
  <EndProperty Name="Course">
    <ScalarProperty Name="CourseID" ColumnName="CourseID" />
  </EndProperty>
  <ModificationFunctionMapping>
    <InsertFunction FunctionName="SchoolModel.Store.InsertCourseInstructor" >   
      <EndProperty Name="Course">
        <ScalarProperty Name="CourseID" ParameterName="courseId"/>
      </EndProperty>
      <EndProperty Name="Person">
        <ScalarProperty Name="PersonID" ParameterName="instructorId"/>
      </EndProperty>
    </InsertFunction>
    <DeleteFunction FunctionName="SchoolModel.Store.DeleteCourseInstructor">
      <EndProperty Name="Course">
        <ScalarProperty Name="CourseID" ParameterName="courseId"/>
      </EndProperty>
      <EndProperty Name="Person">
        <ScalarProperty Name="PersonID" ParameterName="instructorId"/>
      </EndProperty>
    </DeleteFunction>
  </ModificationFunctionMapping>
</AssociationSetMapping>

See Also

Tasks

How to: Define a Model with a Stored Procedure

Other Resources

Walkthrough: Mapping an Entity to Stored Procedures
CSDL, SSDL, and MSL Specifications