Saturday, 7 September 2013

Relatioinship in Mscrm 2011



Relationships:
You can create the following types of the relationships between entities: one-to-many, many-to-one, many-to-many, and self-referential.

The records for a many-to-many or self-referential relationship are stored in an intersect entity. After a relationship is defined, use the AssociateRequest message or the Associate method to create a link between the specified records, and use the DisassociateRequest message or the Disassociate method to remove a link between the specified records.

1: N Relationship
In the one-to-many and many-to-one relationships, some actions on the parent entity record affect the child entity records. The actions that have cascading behavior include: Assign, Delete, Merge, Share, Unshare and Reparent. For more information, see Entity Relationship Behavior.

Type of Behaviors in 1:N relationship:
·         Parental: perform action on all child records. E.g.: if parent record is deleted, system deletes all the associated child records
·         Referential: does perform any action on the child records. E.g.: if parent record is deleted, system leaves the child records undeleted

·         Reference Restrict: prevents the parent record from being deleted if it has child records associated to it
·         Cascade Configuration: allows to configure the following actions on the child entities

Action
Description
Cascade Active
Perform the action on all active referencing (child) entity records associated with the referenced (parent) entity record.
Cascade All
Perform the action on all referencing entity records associated with the referenced entity record.
Cascade None
Do nothing.
Remove Link
Remove the value of the referencing attribute for all referencing entity records associated with the referenced entity record.
Restrict

Prevent the Referencedentity record from being deleted when referencing entities exist.

Cascade User Owned
Perform the action on all referencing entity records owned by the same user as the referenced entity record.


N: N Relationship

Native: Created through N:N configuration wizard provided by MSCRM. It’s a direct relationship and no intersection table is involved.

Advantages and Disadvantages of Native N:N Relationships

The primary advantage of native N:N relationships is how easy they are to create and understand.
However, there are several disadvantages:
§  As I showed above, you cannot use Advanced Find to build a view that contains columns from both sides of the relationship.
§  You also cannot import data using the Import Data Wizard. For example, if you created the N:N between contact and association in CRM and then wanted to import a big list of association members (contacts) and get them attached to the associations while importing…this isn’t possible.
§  You also cannot take advantage of workflows with the native N:N approach. For example, you might want a notification workflow to run automatically when a new member is added to an association. Or you might want a workflow to create a member record when some condition is satisfied. Sadly, neither of these are possible with the native N:N approach.
Manual:A third entity – often referred to as the “junction” or “intersection” entity – is used to contain “instances” of the relationship. Instead of creating a direct N:N, you relate the two entities indirectly, by creating 1:N relationships to the intersection record type.
The disadvantages of the native approach are solved by the manual one:
§  You can create an Advanced Find view on the Membership entity, and include any fields you want in the view, whether from Membership, Contact or Association.
§  If you’ve got some combination of contacts, associations and memberships in spreadsheets, you can import them all into Dynamics CRM. (And for bonus points, the Data Import Wizard in CRM 2011 lets you create custom entities and fields on the fly, as well as associate child to parent records, so you could do everything in one pass: create the custom association and membership entities and import the data!)
§  Workflows can run on the Membership entity, so the scenarios I mentioned above are possible along with anything else you can think of.