Condividi tramite


Condition Element (AssociationSetMapping)

The Condition element in an AssociationSetMapping specifies a logical requirement for the validity of the Association being mapped in the Entity Data Model (EDM). Mapping an association identifies the columns in data tables to which properties of the related entities correspond.

The following AssociationSetMapping element maps the Employee_Employee_ManagerID association defined in conceptual schema definition language (CSDL), in the HumanResources segment of the AdventureWorks database. The following mapping specification relates an Employee entity to another Employee entity designated as manager.

<?xml version="1.0" encoding="utf-8"?>
<Mapping Space="C-S" 
    xmlns:edm="urn:schemas-microsoft-com:windows:storage:mapping:CS" 
    xmlns="urn:schemas-microsoft-com:windows:storage:mapping:CS">
  <EntityContainerMapping CdmEntityContainer="HumanResources"
                           StorageEntityContainer="HumanResources">

    <AssociationSetMapping Name="Employee_Employee_ManagerID"
       TypeName="AdventureWorksHRModel.Employee_Employee_ManagerID"
           StoreEntitySet="Employee">
      <EndProperty Name="Employee">
        <ScalarProperty Name="EmployeeID"
                                     ColumnName="ManagerID" />
      </EndProperty>
      <EndProperty Name="EmployeeManager">
        <ScalarProperty Name="EmployeeID"
                               ColumnName="EmployeeID" />
      </EndProperty>
      <Condition ColumnName="ManagerID" IsNull="false" />
    </AssociationSetMapping>

  </EntityContainerMapping>

Both entities related by this Association are Employee entities. The mapping depends on the Condition specified in the final line of the AssociationSetMappng. For the Association to be valid, it must connect an Employee entity with another Employee entity designated as manager. The storage structure that represents this connection is a foreign key constraint in the ManagerID column of the Employee table. If this condition is Null, the condition is not met and assigning additional details in an instance of the Association would be meaningless. If an Association of this type is created in code when the ManagerID value is Null, the Association will throw an exception when the SaveChanges method is called.

See Also

Concepts

EntityContainerMapping Element (MSL)
Association Element (CSDL)
AssociationSet Element (EntityContainer CSDL)
Association Element (SSDL)
AssociationSet Element (EntityContainer SSDL)
AdventureWorks Complete Model (EDM)