Export (0) Print
Expand All

ComplexTypeMapping Element (MSL)

The ComplexTypeMapping element in mapping specification language (MSL) is a child of the ResultMapping element and 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 complex type.

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

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

The ComplexTypeMapping element can have the following child elements:

Applicable Attributes

The following table describes the attributes that are applicable to the ComplexTypeMapping element.

Attribute Name Is Required Value

TypeName

Yes

The namespace-qualified name of the complex type that is being mapped.

Example

Consider the following stored procedure:

CREATE PROCEDURE [dbo].[GetGrades]
            @student_Id int
            AS
            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 complex type:

<ComplexType Name="GradeInfo">
  <Property Type="Int32" Name="EnrollmentID" Nullable="false" />
  <Property Type="Decimal" Name="Grade" Nullable="true" 
            Precision="3" Scale="2" />
  <Property Type="Int32" Name="CourseID" Nullable="false" />
  <Property Type="Int32" Name="StudentID" Nullable="false" />
</ComplexType>

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

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

See Also

Community Additions

ADD
Show:
© 2014 Microsoft