Entity Relationships in Microsoft Dynamics CRM
Entity Relationships in Microsoft Dynamics CRM is the ability to relate an entity to itself, which is referred as self-referential. Relationships are user friendly and don’t need to be a database administration expert to configure relationships between entities. Microsoft Dynamics CRM supports the following relationships :
- 1:N relationships (one to many).
- N:1 relationships (many to one).
- N:N relationships (many to many).
1:N (one to many) Relationships in Microsoft Dynamics CRM
Entity Relationship defines how records can be related to each other in the database. Adding a lookup field to an entity creates a new 1:N (one-to-many) relationship between the two entities. With the lookup field, One parent record is associated to many child records. Basically it forms the parent-child relationships. A parent object can have many child’s objects but a child object must have only one parent object.
N:1(Many to One) Relationships in Microsoft Dynamics CRM.
With an N:1 relationship, the primary entity is the one you select. Therefore, the entity you are customizing is the related entity.
Example :- if you want a Contact entity to have multiple Account entities associated with it, you apply an N:1 relationship to the Account entity.
N:N (Many to many) Relationships in Microsoft Dynamics CRM.
With an N:N relationship, there is not one primary entity and another secondary or related entity; rather, they both act as both types.
Example:- you might want to have one Contact entity related to many Account entities or one Account related to many Contact entities. You might, for instance, have a Contact with a new person who works for two companies, and each company might have many Contact entities apart from this one.
In this Microsoft Dynamics CRM tutorial, we are going to create 1:N (one-to-many) relationship between Account and Contacts. Where an Account can have many contact records but the same contact can have only one account record related to it.
Create 1:N Relationship in Dynamics 365
It is essential to create a lookup field before creating 1:N relationship in Microsoft Dynamics CRM. To create relationship follow the steps given below :
- Navigate toSettings | Customizations | Customize the System.
Now go to Components and expand your Entity to which you want to create 1:N relationship.
- To create new 1:N Relationships, navigate t0 your Entity and click on 1:N Relationship as shown below.
For a new relationship, in the Relationship Definition section, in the Related Entity list, select the entity to be related. As shown below the related entity will be “Contact“.
- Select whether this will be searchable to not.
- In the Lookup Field section, specify a value for the Display Name field
Enter all the details in Relationship Definition. Lookup Field section, Navigation pane Item for Primary Entity and Relationship Behaviour.
- Click on Save button and publish all your customizations.
- Now go to Mapping and create new Mapping between the Source entity and Target entity.
- Click on New button to create mapping between Account and contact.