In case if your custom code is working with thousands of records use of Entity class with better performance than the early-bound entity types is recommended. However, there is a disadvantage with the fact that you cannot verify entity and attribute names at compile time. If your entities are already defined inside CRM at code time and performance degradation is acceptable,  generation of early-bound types can be used instead with a little help by CrmSvcUtil tool.

An executable file $SDK/Bin/crmsvcutil.exe is a command line utility, a code generation tool inside your SDK package folder that uses CRM Metadata to generate classes and properties defined for your entities. This means it creates one class for each CRM entity, including generation of custom entities classes and their properties for attributes.

Create runcodegen.cmd file inside Notepad, insert proper values to point to your CRM instance and save it inside SDK/Bin folder. Url can be found by navigation on Settings/Customizations/Developer Resources.

Create runcodegen.cmd file inside Notepad, insert proper values to point to your CRM instance and save it inside SDK/Bin folder. Url can be found by navigation on Settings/Customizations/Developer Resources.

runcodegenPicture

Run Command Prompt as Administrator, positioned inside the SDK/Bin folder with saved file and Run It.

cmdRunCodeGenerator

Because it is generating a one large file it can even last for a minute or two, but if your file was correctly written soon you can find your generated output file inside of a folder.

VisualStudioLateEarlyBound

By creating new solution inside Visual Studio, and adding Existing Item inside project it is possible to use early bound classes. As you can see on the picture instead of referencing to Entity class, now it is possible to reference the Account class.

As we already mentioned, good side of using early bound classes is that we would get the compile error right at the beginning if we try to debug a project solution, instead of the runtime error for late bound classes. Also we do not need to check names of the attributes by checking the fields of entities, and IntelliSense can help us while writing code by suggesting the name of the property for each entity class, and it is suitable if we are working with large number of attributes.

The bad side is that if we make any changes to entities or attributes on our CRM data model it is mandatory to re-generate code so we can reuse it inside Visual Studio. If we want we can mix and match with different techniques, early and late bound types. More details can be found here: https://msdn.microsoft.com/en-us/library/gg328499.aspx

Other approaches for generating early bound types include using of a CRM Developer Toolkit or to generate a wrapper classes by right-clicking the CRM Explorer inside of Visual Studio solution connected to your CRM instance. Keep in mind that the command line utility gets you the most control over the options that are being passed when we do the code generation.