This project has moved. For the latest updates, please go here.

Incorporate enum-classes in entity-classes

Feb 24, 2015 at 2:17 PM
When generating the classes for the entities I get the State-enums in the same file as where the entity-class is stored (like AccountState which in the same file where public partial class Account is made). I choose to have 1 file per entity. Is it possible to generate other OptionSet enums for an entity also in the entity-file? Now I generate them seperately (entities and enums), which is ok of course, but since having lots and lots of custom entities with lots of enums, resulting in even more files, I would love the enums to be in the same file as where the entity-class is stored.
If there is a design-reason why I shouldn't want to have this, I would love to hear it. I am actually quite new to C#-development.
Coordinator
Feb 24, 2015 at 3:22 PM
Is it possible, probably, but not probable ;)

Let me explain. The reason that you're seeing the State-enums in the Entity class is that they get created with entities as the OOB functionality of the CrmSvcUtil.exe found in the SDK. I'm guessing this is because of two reasons, State-Enums can't change, and they are specific to that particular entity. All other Option Sets could possibly change, and they are not always specific to a particular entity (Global Option Sets are shared among multiple entities). Later on Microsoft created a method for creating these Option Sets, but they made it a separate process. The EBG (Early Bound Generator) abstracts this away from you the end user, but it is still separate calls to CRM for entities and Option Sets.

Splitting up the files is done after the DOM is created, and I added logic to include the State-enums in the Entity file, but since they are separate files, I don't have an option to include these files. It would have to be a straight string merge of the files and since there is no guarantee that a user does both at the same time, the cost doesn't justify the means. You're welcome to write your own utility that performs it for you though....
Marked as answer by hulk2484 on 2/24/2015 at 8:27 AM
Feb 25, 2015 at 9:09 AM
Ok, thx for your reply. Guessed something like that was the issue. Well, gonna have to live with that for the moment :-). Great tool!