AssociationEnd Element (MSL)

The AssociationEnd element in mapping specification language (MSL) is used when the modification functions of an entity type in the conceptual model are mapped to stored procedures in the underlying database. If a modification stored procedure takes a parameter whose value is held in an association property, the AssociationEnd element maps the property value to the parameter. For more information, see the example below.

For more information about mapping modification functions of entity types to stored procedures, see ModificationFunctionMapping Element (MSL) and Walkthrough: Mapping an Entity to Stored Procedures.

The AssociationEnd element can have the following child elements:

Applicable Attributes

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

Attribute Name Is Required Value

AssociationSet

Yes

The name of the association that is being mapped.

From

Yes

The value of the FromRole attribute of the navigation property that corresponds to the association being mapped. For more information, see NavigationProperty Element (CSDL).

To

Yes

The value of the ToRole attribute of the navigation property that corresponds to the association being mapped. For more information, see NavigationProperty Element (CSDL).

Example

Consider the following conceptual model entity type:

<EntityType Name="Course">
  <Key>
    <PropertyRef Name="CourseID" />
  </Key>
  <Property Type="Int32" Name="CourseID" Nullable="false" />
  <Property Type="String" Name="Title" Nullable="false" MaxLength="100" 
            FixedLength="false" Unicode="true" />
  <Property Type="Int32" Name="Credits" Nullable="false" />
  <NavigationProperty Name="Department" 
                      Relationship="SchoolModel.FK_Course_Department" 
                      FromRole="Course" ToRole="Department" />
</EntityType>

Also consider the following stored procedure:

CREATE PROCEDURE [dbo].[UpdateCourse]
        @CourseID int,
        @Title nvarchar(50),
        @Credits int,
        @DepartmentID int
        AS
        UPDATE Course SET Title=@Title, 
                Credits=@Credits,
                DepartmentID=@DepartmentID
        WHERE CourseID=@CourseID;

In order to map the update function of the Course entity to this stored procedure, you must supply a value to the DepartmentID parameter. The value for DepartmentID does not correspond to a property on the entity type; it is contained in an independent association whose mapping is shown here:

<AssociationSetMapping Name="FK_Course_Department" 
                       TypeName="SchoolModel.FK_Course_Department" 
                       StoreEntitySet="Course">
  <EndProperty Name="Course">
    <ScalarProperty Name="CourseID" ColumnName="CourseID" />
  </EndProperty>
  <EndProperty Name="Department">
    <ScalarProperty Name="DepartmentID" ColumnName="DepartmentID" />
  </EndProperty>
</AssociationSetMapping>

The following code shows the AssociationEnd element used to map the DepartmentID property of the FK_Course_Department association to the UpdateCourse stored procedure (to which the update function of the Course entity type is mapped):

<EntitySetMapping Name="Courses">
  <EntityTypeMapping TypeName="SchoolModel.Course">
    <MappingFragment StoreEntitySet="Course">
      <ScalarProperty Name="Credits" ColumnName="Credits" />
      <ScalarProperty Name="Title" ColumnName="Title" />
      <ScalarProperty Name="CourseID" ColumnName="CourseID" />
    </MappingFragment>
  </EntityTypeMapping>
  <EntityTypeMapping TypeName="SchoolModel.Course">
    <ModificationFunctionMapping>
      <UpdateFunction FunctionName="SchoolModel.Store.UpdateCourse">
        <AssociationEnd AssociationSet="FK_Course_Department" 
                        From="Course" To="Department">
          <ScalarProperty Name="DepartmentID" 
                          ParameterName="DepartmentID" 
                          Version="Current" />
        </AssociationEnd>
        <ScalarProperty Name="Credits" ParameterName="Credits" 
                        Version="Current" />
        <ScalarProperty Name="Title" ParameterName="Title" 
                        Version="Current" />
        <ScalarProperty Name="CourseID" ParameterName="CourseID" 
                        Version="Current" />
      </UpdateFunction>
    </ModificationFunctionMapping>
  </EntityTypeMapping>
</EntitySetMapping>

See Also

Other Resources

CSDL, SSDL, and MSL Specifications
Modeling and Mapping