This documentation is archived and is not being maintained.

InsertFunction Element (MSL)

The InsertFunction element in mapping specification language (MSL) maps the insert function of an entity type or association in the conceptual model to a stored procedure 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).

Cc716749.note(en-us,VS.100).gifNote:
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.

The InsertFunction element can be a child of the ModificationFunctionMapping element and applied to the EntityTypeMapping element or the AssociationSetMapping element.

InsertFunction Applied to EntityTypeMapping

When applied to the EntityTypeMapping element, the InsertFunction element maps the insert function of an entity type in the conceptual model to a stored procedure.

The InsertFunction element can have the following child elements when applied to an EntityTypeMapping element:

Applicable Attributes

The following table describes the attributes that can be applied to the InsertFunction element when applied to an EntityTypeMapping element.

Attribute Name Is Required Value

FunctionName

Yes

The namespace-qualified name of the stored procedure to which the insert function is mapped. The stored procedure must be declared in the storage model.

RowsAffectedParameter

No

The name of the output parameter that returns the number of affected rows.

Example

The following example is based on the School model and shows the InsertFunction element used to map insert function of the Person entity type to the InsertPerson stored procedure. The InsertPerson stored procedure is declared in the storage model.

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

InsertFunction Applied to AssociationSetMapping

When applied to the AssociationSetMapping element, the InsertFunction element maps the insert function of an association in the conceptual model to a stored procedure.

The InsertFunction element can have the following child elements when applied to the AssociationSetMapping element:

Applicable Attributes

The following table describes the attributes that can be applied to the InsertFunction element when it is applied to the AssociationSetMapping element.

Attribute Name Is Required Value

FunctionName

Yes

The namespace-qualified name of the stored procedure to which the insert function is mapped. The stored procedure must be declared in the storage model.

RowsAffectedParameter

No

The name of the output parameter that returns the number of rows affected.

Example

The following example is based on the School model and shows the InsertFunction element used to map insert function of the CourseInstructor association to the InsertCourseInstructor stored procedure. The InsertCourseInstructor stored procedure is 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

Show: