Partilhar via


ScalarProperty Element (MSL)

The ScalarProperty element in mapping specification language (MSL) maps a property on a conceptual model entity type, complex type, or association to a table column or stored procedure parameter in the underlying database.

Note

Stored procedures to which modification functions are mapped must be declared in the storage model. For more information, see Function Element (SSDL).

The ScalarProperty element can be a child of the following elements:

As a child of the MappingFragment, ComplexProperty, or EndProperty element, the ScalarProperty element maps a property in the conceptual model to a column in the database. As a child of the InsertFunction, UpdateFunction, or DeleteFunction element, the ScalarProperty element maps a property in the conceptual model to a stored procedure parameter.

The ScalarProperty element cannot have any child elements.

Applicable Attributes

The attributes that apply to the ScalarProperty element differ depending on the role of the element.

The following table describes the attributes that are applicable when the ScalarProperty element is used to map a conceptual model property to a column in the database:

Attribute Name Is Required Value

Name

Yes

The name of the conceptual model property that is being mapped.

ColumnName

Yes

The name of the table column that is being mapped.

The following table describes the attributes that are applicable to the ScalarProperty element when it is used to map a conceptual model property to a stored procedure parameter:

Attribute Name Is Required Value

Name

Yes

The name of the conceptual model property that is being mapped.

ParameterName

Yes

The name of the parameter that is being mapped.

Version

No

Current or Original depending on whether the current value or the original value of the property should be used for concurrency checks.

Example

The following example shows the ScalarProperty element used in two ways:

  • To map the properties of the Person entity type to the columns of the Person table.

  • To map the properties of the Person entity type to the parameters of the UpdatePerson stored procedure. The stored procedures are 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>

Example

The next example shows the ScalarProperty element used to map the insert and delete functions of a conceptual model association to stored procedures in the database. The stored procedures are 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