Microsoft Dynamics CRM supports a rich entity model. This topic describes aspects that are common across many or all entities within the system
Actions on Entities
Actions on Entities
The following table describes the actions allowed on entity instances in general. Not all actions are allowed on all types of entities. For simplicity, the following table uses the term "record" to mean an instance of an entity.
Action | Privilege | Description |
Assign | Assign | This action changes ownership of the target record. When an entity is assigned to another user, the previous owner still has access to this entity if the organization.shareWithPreviousOwnerOnAssign property is set to true. However, the previous owner will no longer have ownership of the entity. |
Create | Create | This action creates a record of a specific entity type. |
Delete | Delete | This action deletes a record and potentially deletes child records based on cascading rules for the entity relationship. For more information, see Cascading Rules. |
Retrieve | Retrieve | This action retrieves a record from the database. |
Share | Share | This action allows a caller to grant or revoke access to a record to another user or team. Sharing is performed by using the GrantAccess, ModifyAccess, and RevokeAccess messages. |
Update | Update | This action lets you modify the contents of a record. |
Append | The record can be appended to another record. For example, a note can be added to an opportunity if the caller has append rights on the note and append to rights on the opportunity. | |
Append To | Append to is the opposite behavior from append. You can append to the record. For example, a note can be added to an opportunity if the caller has append rights on the note and append to rights on the opportunity. |
Entity Ownership
Entity Ownership
There are several types of entity ownership. Entities are typically owned by the organization or by a user. Custom entities always have one of these types of ownership. There are some system entities that do not have an owner. The type of ownership defines some operations that can be performed on an instance of the entity type. The following table describes the ownership properties.
Ownership Type | Description |
Organization Owned | Organization-owned entities typically contain data involving something that belongs to or that can be viewed by the whole organization. Organization-owned entities cannot be assigned or shared. For example, products are owned by the organization. |
Business Owned | Business-owned entities belong to a business unit. |
User Owned | User-owned entities are associated with a user. User-owned entities typically contain data that relates to customers, such as accounts or contacts. Security can be defined according the business unit for the user. |
None | The entity is not owned by another entity. For example, the uom (unit-of-measure) and workflowlog (workflow log) entities are not owned by another entity. |
The ownership type is represented by the EntityMetadata.OwnershipType property.
Example
When you create an entity instance, the ownerid attribute is automatically set to be the ID of the authenticated user. For more information, see Web Service Authentication and Impersonation. The following code shows you how to assign a different owner.
newAccount.ownerid = new Owner(); // Set the value to the ID of a user in the system. newAccount.ownerid.Value = new Guid("556E49E6-581B-4B61-91E4-6A7E7E8E6A9E"); // Set the type code of the owner. newAccount.ownerid.type = EntityName.systemuser.ToString(); // Now create or update the entity instance.
Entity RelationshipsEntity Relationships
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.
Hierarchical Relationships
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.
Self-Referential Relationships
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.
Cascading RulesCascading Rules
In Microsoft Dynamics CRM you can control how certain actions on a parent record affect child records. The actions that have cascading behavior are as follows:
- Assign
- Delete
- Merge
- Reparent
- Share
- Unshare
The cascading rules are described in the following table.
Rule | Description |
Cascade All | Perform the action on the specified entity instance and all related entity instances. |
Cascade None | Perform the action on the specified entity instance only. Do not cascade to related entity instances. |
Cascade Active | Perform the action on the specified entity instance and all related entity instances that are active or open. |
Cascade User Owned | Perform the action on the specified entity instance and all related entity instances that are owned by the same user as this entity. |
Remove Link | Perform the action on the specified entity instance and remove the link to the related entity instance. No changes are made to the related entity instance. |
Restrict | Applies to delete only. The delete is not allowed if there are other entity instances that reference the ID of the entity instance being deleted. |
These relationship types are represented by the following properties in the relationship metadata:
OneToManyMetadata.CascadeAssign
OneToManyMetadata.CascadeDelete
OneToManyMetadata.CascadeMerge
OneToManyMetadata.CascadeReparent
OneToManyMetadata.CascadeShare
OneToManyMetadata.CascadeUnshare