Convert a late bound type to an early bound type

1 min read

Summary

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: https://docs.microsoft.com/en-us/dynamics365/customer-engagement/developer/org-service/use-early-bound-entity-classes-code

You must be logged in to post a comment.