Convert a late bound type to an early bound type


You’ll often find a lot of Dynamics 365 sample code (especially in forums) written in late-bound syntax.

Make the changes

In Dynamics 365 for CE, the early-bound code generation tool (CrmSvcUtil) creates early-bound entity classes that can be used to access data in Dynamics 365. These classes include one class for each entity in the organisation. The benefits to using early-bound entity classes is that all type references are checked at compile time. This means fewer mistakes during the development phase.

The classes created by the CrmSvcUtil 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.

However, if you prefer to mix the two development styles, then you can convert between the two by simply using the .ToEntity() method.

Account record = entity.ToEntity();

For more information on early-bound types, refer to Microsoft’s documentation:

Leave a comment