[Applies to: Microsoft Dynamics CRM 4.0]
Find the latest SDK documentation: CRM 2015 SDK
You can create the following types of relationships: one-to-many, many-to-one, many-to-many, and self-referential. Many-to-many and self-referential relationships are new in Microsoft Dynamics CRM 4.0.
A hierarchical relationship allows for each child entity instance to store a reference to one parent entity instance. A parent entity instance can be referenced by an unlimited number of child entity instances. The parent entity instance can display all the child entity instances in an associated view. The relationship definition for an organization can be accessed by using the MetadataService Web service.
Hierarchical relationships let you configure several behaviors that affect data integrity and the business rules in your organization.
When you create or edit a relationship between entities in Microsoft Dynamics CRM, you must start from one of the entities. Which entity is not important because only one relationship will be created. But the terminology used depends on whether you start from the primary entity or the related entity.
A 1:N (one-to-many) Relationship is a hierarchical relationship created or viewed from the primary entity. Any one entity instance from the primary entity can be referenced by many entity instances from the related entity.
An N:1 (many-to-one) Relationship is a hierarchical relationship created or viewed from the related entity. Many entity instances from the related entity can reference any one entity instance from the primary entity.
Remember that the same relationship can be viewed from either of the two entities that participate in the relationship.
Both relationships are represented by the OneToManyMetadata class. Notice that the Microsoft Dynamics CRM Web application uses the terms primary entity and related entity while the metadata service uses the terms referenced entity and referencing entity.
N:N (many-to-many) Relationships
A many-to-many relationship lets users relate one or more entity instances from another entity to an entity instance of the current entity. A many-to-many relationship is reciprocal. Therefore, entity instances can be related from either entity. A many-to-many relationship may also be self-referential. This means that one or more other entity instances of the current entity can be related to an entity instance of the same entity.
This kind of relationship is represented by the ManyToManyMetadata class.
When you create a many-to-many relationship, an intersect table is created. You can use the intersect tables in the QueryExpression for a RetrieveMultiple query, but you cannot retrieve the intersect table records directly with the RetrieveMultiple method. To retrieve the records in an intersect table, you must use the Fetch method. For more information, see Using Intersect Tables.
In a self-referential relationship, an entity has a relationship with itself. Both hierarchical relationships and many-to-many relationships can be self-referential. This allows entity instances to be directly associated with other entity instances of the same type. For example, opportunities can be linked to related opportunities.
The only limitation to self-referential relationships is that entity instances cannot be related to themselves in a parental relationship. This creates a circular reference.
- AssociateEntities Message
- AutoMapEntity Message
- DisassociateEntities Message
- MetadataService Messages