ModificationFunctionMapping 元素 (MSL)

以映射规范语言 (MSL) 表示的 ModificationFunctionMapping 元素将概念模型实体类型的插入、更新和删除函数映射到基础数据库中的存储过程。 ModificationFunctionMapping 元素还可以将概念模型中用于多对多关联的插入和删除函数映射到基础数据库中的存储过程。 将修改函数映射到其中的存储过程必须在存储模型中声明。 有关更多信息,请参见 Function 元素 (SSDL)

Cc716778.note(zh-cn,VS.100).gif注意:
如果没有将实体类型的插入、更新或删除这三种操作全部映射到存储过程,则在运行时执行的情况下未映射的操作将失败且会引发 UpdateException

Cc716778.note(zh-cn,VS.100).gif注意:
如果将继承层次结构中的一个实体的修改函数映射到存储过程,则必须将该层次结构中所有类型的修改函数都映射到存储过程。

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>

示例

下面的示例演示了 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>

另请参见

任务

如何:使用存储过程定义模型(实体框架)

其他资源

Walkthrough: Mapping an Entity to Stored Procedures
CSDL、SSDL 和 MSL 规范