This documentation is archived and is not being maintained.

ResultMapping Element (MSL)

The ResultMapping element in mapping specification language (MSL) defines the mapping between a function import in the conceptual model and a stored procedure in the underlying database when the following are true:

  • The function import returns a conceptual model entity type or complex type.

  • The names of the columns returned by the stored procedure do not exactly match the names of the properties on the entity type or complex type.

By default, the mapping between the columns returned by a stored procedure and an entity type or complex type is based on column and property names. If column names do not exactly match property names, you must use the ResultMapping element to define the mapping. For an example of the default mapping, see FunctionImportMapping Element (MSL).

The ResultMapping element is a child element of the FunctionImportMapping element.

The ResultMapping element can have the following child elements:

No attributes are applicable to the ResultMapping Element.


Consider the following stored procedure:

CREATE PROCEDURE [dbo].[GetGrades]
            @student_Id int
            SELECT 	EnrollmentID as enroll_id, 
					Grade as grade, 
					CourseID as course_id, 
					StudentID as student_id 
			FROM dbo.StudentGrade
            WHERE StudentID = @student_Id

Also consider the following conceptual model entity type:

<EntityType Name="StudentGrade">
    <PropertyRef Name="EnrollmentID" />
  <Property Name="EnrollmentID" Type="Int32" Nullable="false" 
            annotation:StoreGeneratedPattern="Identity" />
  <Property Name="CourseID" Type="Int32" Nullable="false" />
  <Property Name="StudentID" Type="Int32" Nullable="false" />
  <Property Name="Grade" Type="Decimal" Precision="3" Scale="2" />

In order to create a function import that returns instances of the previous entity type, the mapping between the columns returned by the stored procedure and the entity type must be defined in a ResultMapping element:

<FunctionImportMapping FunctionImportName="GetGrades"
                       FunctionName="SchoolModel.Store.GetGrades" >
    <EntityTypeMapping TypeName="SchoolModel.StudentGrade">
      <ScalarProperty Name="EnrollmentID" ColumnName="enroll_id"/>
      <ScalarProperty Name="CourseID" ColumnName="course_id"/>
      <ScalarProperty Name="StudentID" ColumnName="student_id"/>
      <ScalarProperty Name="Grade" ColumnName="grade"/>

See Also