共用方式為


ModificationFunctionMapping 項目 (MSL)

對應規格語言 (MSL) 中的 ModificationFunctionMapping 項目會將概念模型實體類型的插入、更新和刪除函式對應至基礎資料庫中的預存程序。ModificationFunctionMapping 項目也可以將概念模型中多對多關聯的插入和刪除函式對應至基礎資料庫中的預存程序。修改函式所對應的預存程序必須在儲存體模型中宣告。如需詳細資訊,請參閱Function 項目 (SSDL)

注意

如果沒有將實體類型的 [插入]、[更新] 和 [刪除] 三種作業都對應到預存程序,則若在執行階段中執行未對應的作業,且擲回 UpdateException,未對應的作業會失敗。

注意

如果繼承階層架構中某個實體的修改函式已對應至預存程序,則階層架構中所有類型的修改函式都必須對應至預存程序。

ModificationFunctionMapping 項目可以是 EntityTypeMapping 項目AssociationSetMapping 項目的子項目。

ModificationFunctionMapping 項目可以擁有下列子項目:

沒有屬性適用於 ModificationFunctionMapping 項目。

範例

下列範例會示範 School 模型中之 People 實體集的實體集對應。除了 Person 實體類型的資料行對應外,還顯示 Person 類別的插入、更新和刪除函式的對應。對應至的函式會在儲存體模型中宣告。

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

範例

下列範例會示範 School 模型中之 CourseInstructor 關聯的關聯集對應。除了 CourseInstructor 關聯的資料行對應外,還顯示 CourseInstructor 關聯的插入和刪除函式的對應。對應至的函式會在儲存體模型中宣告。

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

請參閱

工作

Walkthrough: Mapping an Entity to Stored Procedures

其他資源

How to: Define a Model with a Stored Procedure

CSDL、SSDL 和 MSL 規格