Entity Developer for NHibernate supports the use of enum types in models.
Enumerated type is a distinct type that consists of a set of named constants. The NHibernate enum type definitions reside in the conceptual layer. The enum type has an underlying type (which can be SByte, Byte, Int16, Int32, or Int64; Int32 is used as the default underlying type if none has been specified).
Enumerated types can have zero or more members. A defined member must have a unique name (note that names are case-sensitive) and may have a value. If the value for the member is not specified, then the value is calculated based on the value of the previous member (through incrementing by one) or set to 0 if there is no previous member. If the value for a given member is specified, it must be in the range of its enum underlying type. Values can be specified only for some of the members; several members can have the same value.
Note also that, when Updating Database from Model is performed within the Model-First approach, for an entity with a property whose type is set to Enum, the type of the corresponding column that is created in the database is assigned based on the underlying type of the enum.
Adding a New Enum Type to a Model
To add a new enum type to a model and to display it on the diagram surface, perform the following sequence of actions:
The newly created enum type is displayed in the Enum Types node of the Model Explorer window. If needed, drag it to the diagram area. |
Storing Enum Property Values in Database
NHibernate allows storing values of properties, having enum type, in the database in two ways: as string values (enum member names are used) or as integer values (enum member values or default values are used). By default, they are stored as integer values. You can change how they are stored model-wide by setting the Default Enum Storage Mode property for the model in Model Properties or in the Model Settings dialog box. If you want to override this model-wide setting for some class or complex type property, you can change the value of its Enum Storage Mode property in the Properties window. |
To add a member of an existing enum type, perform the following sequence of actions:
A new member with default properties is added to the selected enum type. |
To modify a member of an existing enum type, perform the following sequence of actions:
The selected enum type is successfully modified. |
To delete an existing enum type use one of the following options:
Entity Developer will then ask you whether you want to delete the object from the model too. If the enum type being deleted is assigned as the type of a property of an entity in the model, after the standard confirmation dialog the following warning is displayed:
Using this dialog, select the appropriate action. |
Entity Developer can work with external enums. These are enums that are already defined in your project, and they should not be generated by Entity Developer. For such enums you may omit member definition. When you specify their name, you need to enter the full name including the namespace, containing the enum. To define an enum as external, select the Is External check box in its editor or set its Is External property value to True in the Properties window. |