Association Element (CSDL)

An association specifies a logical relationship between entities in the Entity Data Model (EDM). An association is declared and defined in the conceptual schema using conceptual schema definition language (CSDL).

The following syntax shows the declaration and definition of an association between two entities of the same type. Both ends of the association are employee entities. One employee is the manager and the other reports to the manager.

The syntax shown here includes the Schema element with the Namespace and Alias of the Adventure Works Human Resources Model being defined. Also included is the declaration of the Employee entity that is used in the Association.

<?xml version="1.0" encoding="utf-8"?>
<Schema Namespace="AdventureWorksHRModel"
Alias="Self" xmlns="">

  <EntityType Name="Employee">
      <PropertyRef Name="EmployeeID" />
    <Property Name="EmployeeID" Type="Int32" Nullable="false" />
    <Property Name="NationalIDNumber" Type="String" Nullable="false" />
    <Property Name="LoginID" Type="String" Nullable="false" />
    <Property Name="Title" Type="String" Nullable="false" />
    <Property Name="BirthDate" Type="DateTime" Nullable="false" />
    <Property Name="Gender" Type="String" Nullable="false" />
    <Property Name="HireDate" Type="DateTime" Nullable="false" />
    <Property Name="SalariedFlag" Type="Boolean" Nullable="false" />
    <Property Name="ModifiedDate" Type="DateTime" Nullable="false" />
<!- Some employee properties ommitted for brevity -->

    <NavigationProperty Name="Employee1"
        FromRole="Employee" ToRole="Employee1" />


  <Association Name="Employee_Employee_ManagerID">
    <End Role="Employee" Type="Self.Employee" Multiplicity="0..1" />
    <End Role="Employee1" Type="Self.Employee"
                                              Multiplicity="*" />

The Association element specifies a logical relationship between Employee entities, as indicated by the Type assignments of the End properties in the Association. Both ends of the association are of the Employee type. One of the employees is designated as Employee1 by the Role attribute of an End property in the Association. The Multiplicity attribute of the End attributes in this example indicate that an Employee who is a manager can manage any number of Employee1 instances. The NavigationProperty in the Employee definition shows the linkage between an employee who is a manager and managed employees.

Type assignments in associations must use fully qualified names. In this example, the type assignment uses the Self Alias for the AdventureWorksHRModel namespace.

See Also

Community Additions