Show TOC

Implementation Support for AssociationLocate this document in the navigation structure

Use

In Service Builder, an entity can be related to another entity through association. The association is a relationship that has two ends, with each end defining an entity type in the relationship.

Service Builder can generate code in the DPC base class that implements navigation at runtime, from any end of the relationship.

Prerequisites

Make sure that you have the following:

  • An association with referential constraints.

  • Operation mapping for GetEntity (Read), or, GetEntitySet (Query), is defined for the Dependent entity to which you want to navigate.

    In case the cardinality of the Dependent entity defined in the association is 0..1, or 1, you must map the GetEntity operation.

    In case the cardinality is n, or, 0..n, you must map the GetEntitySet operation.

Referential Constraint

The Principal entity must have a cardinality of 1, or 0..1, and you must specify all key properties of the Principal entity when defining the referential constraint.

Navigation Properties

Navigation properties enable users to traverse the association between two entity types. Where an entity has a navigation property, you can navigate between that entity to the related entity in the relationship.

Example

The following example shows two scenarios of navigation from Customer to SalesOrder, and then back to Customer.

  • Standard navigation scenario from Customer to its related SalesOrder list.

    1. Create the association from Customer, to Entity SalesOrder.

    2. Define the cardinality to be from 1..1, or 0..1 to 1..n, or 0..n. Where the cardinality for the principal entity must be 1..1, or, 0..1.

    3. Define a navigation property for the Principal entity, Customer.

    4. In the Referential Constraints page of the wizard, the key property for the principal entity, Customer, is automatically specified as the principal key.

    5. In Dependent Property, select the property from which you want to obtain results, and follow the wizard to define the relationship.

  • Opposite navigation scenario from SalesOrder details to its Customer details.

    1. Create the association from Customer, to SalesOrder.

    2. Define the cardinality to be from 1..1, or 0..1, to 1..1, or 0..1. Where the cardinality for the principal entity must be 1..1, or, 0..1.

    3. Define a navigation property for the Dependent entity, SalesOrder.

    4. In the Referential Constraints page of the wizard, the key property for the principal entity, Customer, is automatically specified as the principal key.

    5. In Dependent Property, select the property from which you want to obtain results, and follow the wizard to define the relationship.

    When you try to navigate from SalesOrder details to Customer details, the Read operation of SalesOrder is executed, and from the read response, the customer number is extracted. This is then used as a key in a call to get Customer details.