官术网_书友最值得收藏!

ERD basics

Microsoft Dynamics CRM 2011 uses SQL Server as its database backend. There are two main databases that are created after the CRM server is initially set up. The MSCRM_CONFIG database, which is the one that holds different organizations' data and general configurations. The other is a database for the organization itself, with a name like <organizationname>_MSCRM. Depending on the number of CRM organizations you have in the system, you will have the same number of databases ending with _MSCRM with similar database schemas. The only difference between the organizations' databases would be the specific customizations on the entities and fields.

Microsoft Dynamics CRM 2011 uses the concept of entities to name, which in a database language would be like a table. An entity is usually a noun such as a person or house. Dynamics CRM comes with lot of entities already created in the system, such as Account, Contact, and Invoice.

As in any table, the entities contain fields. Each field represents an attribute in the entity. Some examples of fields are First Name, Name, and Address.

Dynamics CRM 2011 has the following types of fields:

  • Single line of text
  • Option set
  • Two options
  • Whole number
  • Floating point number
  • Decimal number
  • Currency
  • Multiple lines of texts
  • Date and time
  • Lookup
    Note

    You can go to http://technet.microsoft.com/en-us/library/gg328507.aspx for a reference of the types of fields used in the Microsoft Dynamics CRM SDK.

Dynamics CRM is a structured system and hence it manages everything in entities. Once you create a field in CRM, you won't be able to change the type of field as you would be able to in Microsoft SharePoint.

For any entity you create in CRM, the system will create different objects in SQL: it will create two tables, one with the name of the entity plus the Base suffix and another table with the same name plus the ExtensionBase suffix.

For example, if we create an entity called Project, the following two tables will be created:

  • New_ProjectBase
  • New_ProjectExtensionBase

Notice that the New_ prefix comes with the default publisher of the solution on which we created the custom entity, and can be changed by creating another publisher.

Apart from the tables, there will be two views that CRM will also create in the SQL Server database:

  • New_project
  • Filterednew_project

The first view, new_project, will return the join of the two tables New_ProjectBase and New_ProjectExtensionBase as these two tables have a one-to-one relationship because they share the same primary key, new_projectId. All the IDs in CRM are GUIDS, which are unique identifiers.

The second view is similar to the first one but with the addition of capacity to control the security of the results based on the calling user. So if this view is selected by a customer service representative, it will return only the records this user has permissions to see, and the first view won't validate any permissions and would always return all the records.

For these reasons, it is recommended to always use the filtered views when querying the records in our reports. That way we can be sure that we will only display information that the user who runs the report is allowed to see.

Another benefit of using views is that you not only get the fields of one table, such as the Base table, but also the fields from the ExtensionBase suffix plus the option set values that are also stored on a separated table.

Relationship types

The entities in Dynamics CRM can be related in the following ways:

  • 1:N (one-to-many)
  • N:1 (many-to-one)
  • N:N (many-to-many)
    Note

    For normalization purposes, Dynamics CRM doesn't allow 1:1 (one-to-one) relationships.

    If you want to review the ERD of your CRM system and custom entities, you can download the solution I have published in CodePlex, which is located at http://crm2011erd.codeplex.com/.

When you go to the Dynamics CRM interface having the system administrator or system customizer role, you can go to Settings | Customizations | Customize the System. Now expand Entities and select any entity, for example, Account. You will see the relationships listed as shown in the following screenshot:

One-to-many relationships (1:N)

These relationships are created when you need to have more than one record of an entity related to a single record of another entity. For example, you can have an account that has more than one contact. In Dynamics CRM, there will be a lookup control in the Contact entity to show the related account, such as the Parent Customer field shown in the following screenshot:

In the Account form, there will be a new entry added to the sitemap with the name of Contacts to show the related contact entries as shown in the following screenshot:

In the Customization section of the Account entity, you will see these 1:N relationships, and on opening it you will see the following details page:

Many-to-one relationships (N:1)

On the other hand, if we are looking at the Contact entity, we will see the same relationship we described in the 1:N example, but backwards. So if we open the Contact entity and go to the N:1 relationships, we will see the same relation we saw in the Account entity under the 1:N relationships.

Note

It is important to know that when we create any type of relationship between two entities, we need to publish both entities for the changes to take effect. Similarly, when we want to export one entity, we will also need to include the related entities in our solution file to replicate the same customization in another organization or environment.

Many-to-many relationships (N:N)

We use this type of relationship when we need to have one record of an entity that needs to be related to more than one record of another entity and at the same time this entity needs to have more than one record related to the first entity. For example, suppose we have a marketing list that can contain more than one account while at the same time an account can belong to more than one marketing list. In Dynamics CRM, this relationship will look as follows:

In the Account form, there won't be a lookup like in the 1:N relationship, and instead they will be added to the sitemap of both entities. For example, in the Account entity, there will be a node to show the marketing lists and in the marketing lists, there will be a node to show the accounts. In this particular case, they will be shown under the marketing members list. This example shows a particular case of a polymorphic relationship that, at this moment, cannot be created and only exists in the out-of-the-box system.

主站蜘蛛池模板: 比如县| 怀仁县| 清苑县| 镇沅| 思茅市| 镇雄县| 上林县| 商都县| 上蔡县| 清河县| 色达县| 扬中市| 西藏| 谷城县| 滁州市| 龙口市| 攀枝花市| 天柱县| 外汇| 阜城县| 长岛县| 衡阳县| 巍山| 墨脱县| 丰台区| 孟村| 马龙县| 伊金霍洛旗| 武强县| 白山市| 应城市| 大余县| 仲巴县| 蓝山县| 汉阴县| 临西县| 吴堡县| 乡城县| 连城县| 建湖县| 司法|