Enumeration Mapping – Configuration

In order to be able to use your enumeration types in all layers at best, it is important to respect some specific guidelines. The following steps will guide you through the entire configuration process:

  • In the Entities project, create a new file called Enumerations.cs. In this file, inside the namespace, create your enumeration type. If we stick back to our order state example, the enumeration type should look like Figure 1;
01 - Create enum

Figure 1 – Enumeration Type

  • In the Access project, open the Entity Data Model, select the entity type you want to replace with your enumeration type and delete it;
  • Stay on the Entity Data Model and identify an entity type that contains a property that you want to convert to your enumeration type. Right click the property and select the Convert to Enum option (Figure 2);
02 Convert to Enum

Figure 2 – Convert to Enum

  • A configuration window opens up (Figure 3). Specify a name for your enumeration type. This name will be used to create a type that only exists in the Entity Data Model, so it is not mandatory to make it match the name of the enumeration type you created in the first step, but I recommend to do so anyway for clarity reason. The second field to configure is the underlying type of your enumeration. And finally, check the Reference external type box and fill in the editable zone with the fully qualified name of your enumeration type. This last operation is the one that creates the mapping between your enumeration type and the enumeration type of the Entity Data Model.
03 Add Enum Type

Figure 3 – Add Enum Type

Now that this new type has been added to your model, you can reuse it directly in other entity type properties without repeating the last two steps. For this purpose, select the property you want to convert and open the properties window. Open the type list and select your enumeration type that should be available. Once all your modifications are made to the model, don’t forget to run all T4 templates to update all generated files that might be impacted. By those changes.

Advertisements