Share via


Microsoft Dynamics CRM 2011: Naming Convention Pitfalls when Creating Entities, Attributes (Fields) and Relationships

Whenever we start technically developing a Dynamics CRM 2011 project, the first things we do are creating entities, attributes, relationships, forms and views. When I say technical development it means after all the initial project design and documentations are complete.

Before we start development on a Dynamics CRM 2011 project, there are some ground rules we need to lay down. These rules are very important and should be properly documented. All the developers should have visibility to these ground rules so that while developing everybody follows the same rules. These rules can be like code should be in source control, inline documentation, only use of early bound programming model, naming conventions, etc.

One of my favourites is naming conventions. Naming conventions in any programming project means how we name our classes, objects, methods and variables. In Dynamics CRM project it mainly starts with how we name our entities, attributes and relationships.

In CRM 2011 the entities, attributes and relationships have 2 different names associated with them. One is Logical Name and the other is Schema Name. Please read my TechNet Wiki article on the differences between the Schema Names and Logical Names. My TechNet Wiki article talks about the schema name and logical name for entities, but the same can be defined for attributes and relationships.

Let's take an example of a naming convection. Say I want to go in for Pascal Casing and I want to create an entity called "computer monitor". My CRM has "new_" as the customisation prefix set to maintain uniqueness in naming of components. As per Pascal Casing the name of my new entity would be "new_ComputerMonitor".

We have to be careful if we have rules around naming convention. If we don't follow the rules and miss them while creating entities, then we need to do rework. Worst case scenario is to drop and create all the entities, attributes and relationships. This may cause a lot of pain if your CRM project development has a deadline. This kind of naming convention pitfall can be avoided by following the rules carefully. In this article I will explain how to follow Pascal Casing naming convention while creating an entity, a primary attribute, an entity field and a relationship. I will take one example of each.

I will take a scenario of creating an entity called "movie". It will have 2 attributes. One is multiple lines of text called "any important comments". The other is a lookup on entity "contact" called as "director". The lookup in "movie" is a N:1 relationship to "contact".

1) I will create my new entity called "movie". See how I have named this new entity as "new_Movie". When I will save this entity, "new_Movie" will become its schema name and "new_movie" will become its logical name.


Create "Movie" Entity

2) While I am still creating this entity, configuring the primary field, as per naming convention, is important. As seen below I have named the entity's primary key as "new_Name". When I save this entity, a field will be created with schema name as "new_Name" and logical name as "new_name". Be very careful, while naming primary field of an entity. If the rules of naming convention are not followed while naming primary field, then after entity is created, you cannot change it. The only way you can change the name of the primary field is dropping and creating the entity again.


Primary Field for "Movie" Entity

3) After the entity "movie" is created. I will create a field called "any important comments". Please note below the naming convention while naming this field. I have taken first character of every word as uppercase and named it as "new_AnyImportantComments". When I save this field, it will be created with schema name of "new_AnyImportantComments" and logical name of "new_anyimportantcomments".


"Any important comments" Field

4) I will create a N:1 relationship from "movie" to "contact. This lookup will select a director of the movie which is also a contact in CRM. There are 2 places where I have to be careful of the naming convention. One is the name of the relationship and second is the name of the lookup.

The unique name I have given to this relationship is "new_Contact_new_Movie". This name is made up of 3 parts. Since this is a custom relationship so the first part is "new_". The second part is name of the primary entity and is called "Contact". The third part is name of the related entity and is called "new_Movie". So the schema name of this relationship becomes "new_Contact_new_Movie".

The name of the lookup field as per naming convention is called "new_DirectorId". The "Id" part in the name has uppercase letter "I" and lowercase "d".


"Director" Field (N:1 Relationship)

In my article, above, I showed how to follow a naming convention rule while creating components in CRM. Your naming convention rules might differ from mine, but it has to be followed right from the beginning. Or else it will cause a lot of re work which can delay any Dynamics CRM project.

I hope this information about ‘Microsoft Dynamics CRM 2011 - Naming Convention Pitfalls when Creating Entities, Attributes (Fields) and Relationships’ was informative. Please feel free to leave your comments.