Use the early bound entity classes in code

In this article

In Microsoft Dynamics 365 (online & on-premises), the code generation tool (CrmSvcUtil) creates early-bound entity classes that you can use to access business data in Microsoft Dynamics 365. These classes include one class for each entity in your installation, including custom entities. Each time you make customizations to your system, you must regenerate these classes. The classes can be used in any project type or built into a class library. You can use early-bound entity classes when creating applications that use Microsoft Dynamics 365 as well as plug-ins and custom workflow activities. For more information about using the code generation tool, see Create early bound entity classes with the code generation tool (CrmSvcUtil.exe).

The class created by the code generation tool includes all the entity’s attributes and relationships. By using the class in your code, you can access these attributes and be type safe. A class with attributes and relationships is created for all entities in your organization. There is no difference between the generated types for system and custom entities.

Tip

You may experience a situation where there are two sets of early-bound entity classes, perhaps each in its own namespace, compiled into your application. For example, you include one set in your application directly and another set exists in a class library your application is linked to. In this case, you may receive an ArgumentException exception and the following error message:

“A proxy type with the name <entity name> has been defined by another assembly.”

In a situation like this, you can use the EnableProxyTypes method, which takes an Assembly object parameter. This method specifies an assembly that contains the early-bound entity proxy types to use with the organization service proxy. This allows you to use different assemblies for different sets of entity proxy instances.

The following sample shows how to set the email address of a contact entity. For this example, assume that a query has found the record to be changed and the logical name is Contact: