Delen via


DeleteFunction Element (MSL)

The DeleteFunction element in mapping specification language (MSL) maps the delete 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).

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.

DeleteFunction Applied to EntityTypeMapping

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

The DeleteFunction 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 DeleteFunction element when it is applied to an EntityTypeMapping element.

Attribute Name Is Required Value

FunctionName

Yes

The namespace-qualified name of the stored procedure to which the delete 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 DeleteFunction element mapping the delete function of the Person entity type to the DeletePerson stored procedure. The DeletePerson stored procedure is 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>

DeleteFunction Applied to AssociationSetMapping

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

The DeleteFunction 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 DeleteFunction 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 delete 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 DeleteFunction element used to map delete function of the CourseInstructor association to the DeleteCourseInstructor stored procedure. The DeleteCourseInstructor 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

Other Resources

CSDL, SSDL, and MSL Specifications
Modeling and Mapping