Dynamics 365 CRM Entity Relationships Understandings
Entity relationship defines how a specific entity record is related to another entity record. In this post we will discuss what is entity relations and details about this topic. We will learn below points in this article,
- Fundamentals of entity relationship
- Relationship V/s Connections
- Types of Entity Relationships
- Relationship Behaviors
- How to create Relationships
Fundamentals of Entity Relationship
Entity relationships define how records can be related to each other in the database. When you are adding a lookup field to an entity the system creates a new 1:N (one-to-many) relationship between the two entities and lets you put that lookup field in a form. Using lookup field you can associate an entity record with another entity record.
Relationship V/s Connections
Although these two word looks like similar we have to understand when to use connections and when to use Relationships. The below grid speaks about it.
Relationships | Connections |
1. This is a formal relationship between entities | 1. This is less formal relationship betwwen entities |
2. We can configure Relationship behaviors using Entity Relationship | 2. We can configure Connection Role in connections creation. |
3. E.g. : An opportunity without a customer is not accepted so we have an entity relationship between Opportunity and Contact so that we can query and report data efficiently. | 3. E.g.: If one contact is spouse of another contact, or one contact is an employer of another contact, so for such type of relationship we define Connections. |
4. Relationships are defined as 1:N, N:N with additional relationship behavior. | 4. Two entity records are connected by a connection Role such as , Employer, Spouse etc. |
Types of Entity Relationship
There are two types of Relationships while customizing entities using relationships. They are given below.
- 1:N (One-to-Many)
An entity relationship where one entity record for the Primary Entity can be associated to many other Related Entity records because of a lookup field on the related entity.
When viewing a primary entity record you can see a list of the related entity records that are associated with it.
- N:N (Many-to-Many)
An entity relationship that depends on a special Relationship Entity, sometimes called an Intersect entity, so that many records of one entity can be related to many records of another entity.
When viewing records of either entity in a N:N relationship you can see a list of any records of the other entity that are related to it.
Relationship Behavior
When a one-to-many entity relationship exists there are cascading behaviors that can be configured to preserve data integrity and automate business processes. This topic will explain some key concepts and describe how you can configure these cascading behaviors.
We have 4 types of relationship behavior as given below.
- Parental
In a parental relationship between two entities, any action taken on a record of the parent entity is also taken on any child entity records that are related to the parent entity record. if you delete a record in the parent entity, the related child entity records are also deleted; or if you share a parent entity record, the related records from the child entity are also shared. All option are disable for Parental relationship.
- Referential
In a referential relationship between two entities, you can navigate to any related records, but actions taken on one will not affect the other
- Referential, Restrict Delete
Actions taken on parent will not affect child record but parent record cannot be deleted till the child record exists. i.e you cannot delete a record when related records exist.
- Configurable Cascading
You need to specify your setting here.
We can set the cascading behavior for the operations like, Assign, Share, Unshare,Reparent,Delete & Merge. We can have one of the below cascading options while configuring relationship.
The type we are interested here is “Configurable Cascading”. It allows you to decide what type of behavior we need to apply.The useful details of different cascading rules are (note here me is referred to the user on whom you will perform actions)
• Cascade All: Perform action on all of my child records. Like if assigned my account to another user then all my activities, orders, invoices etc are assign to new user including open, completed and other user owned records
• Cascade Active: Perform action on only my active child records
• Cascade User-Owned: Perform action on all my child records which is owned by me
• Cascade None: do nothing to my child records
• Remove Link: remove link from child record
• Restrict: Applies to Delete. The delete is not allowed if there are other entity instances that reference the ID of the entity instance being deleted.
As per Microsoft the definitions of the cascading concept is given below.
The below matrix is specifies the default relationship behavior cascading concept. In the below matrix wherever we have “cannot be changed” means we can not select to choose other option the value is pre-populated by system and can not be changed.This means for example if the behavior is parental then if we assign a record to a new user then all the child entity records will also be assigned to the user automatically due to “Cascade All” behavior.
How to create Relationship
In this section we will understand how we can create a relationship behavior for a 1:N relationship type.
Step-1: Open Dynamics 365 -> Goto Settings Area -> Select Customization->Open Customize the System
Step-2: In the default solution ->Expand the Entity option and select the entity to add relationship
Step-3: In entity -> Select 1: N relationship and add new relationship a sample snapshot given below.
Step-4: Choose the mandatory fields and also the cascading behaviors.
Step-5: Now save it and check a lookup field in referencing entity.