Hardcore CRM: Playing with meta data

One of the advantages of being a software engineer is that you can automate your job. Let some handy tooling do a lot of the dirty work, allowing you to focus on stuff that matters.

Back in the days I used to use metadata to automate my job, which is writing code (below an example of one of my old generators).


As soon as I could lay my hand on a solid relation datamodel, I used to write code to generate code. This resulted in solid and easy to maintain software projects.
A few weeks ago I was training some developers in extending Dynamics CRM. One of the tools being discussed in the training is the SDK tool CrmSvcUtil.exe. A command line tool that you can use to generate C# code, that you can use in your projects. A nice tool, however the tool is generating C# code for every entity available in CRM. Creating a lot of overhead.

As a product developer, I’m not interested in having code for any entity in CRM, I’m interested in having just the code for all entities of the solution I’m working on. I abandoned the CrmSvcUtil tool, and kept thinking of the code generators I wrote in the past.

Instead of reinventing the wheel, I did some research on the web and stumbled on a blog post, in which Simone Tagliaro described how to get all entities for a solution.
Though it was written for CRM 2011, it works like a charm on CRM 2015. This can serve as a perfect basis for the new tool I’m planning to build; An easy to use and flexible code generator powered by Dynamics CRM.

I created a test solution on CRM, containing three entities, fiddled a bit with the code and gave it a shot. I was pleasantly surprised.
I was able to retrieve the metadata for the entities within the solution I defined’.

In the figure below an example of the account entity with the fields specified.


The code used for this, turned out to be pretty straightforward.


In step 1 all solution components (with componenttype=1 (entity)) within the solution (identified by its uniquename) are being retrieved. In step 2 all entities with all metadata within CRM are being retrieved. Finally in step 3 a Linq query is used to filter only those entities that belong to the solution.

Once the data is retrieved, I can iterate through the entities and all attributes. Getting the data I want.

Time to hammer out a new code generator…