Working with enums

Entity Developer for Telerik Data Access supports the use of enum types in models.

Overview

An enumerated type is a distinct type that consists of a set of named constants. 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 the default if none is specified).

Enum members

Enumerated types can have zero or more members. A defined member must:

  • Have a unique name (names are case-sensitive).
  • Have an optional value.

If the value for a member is not specified, it is calculated based on the previous member’s value (incremented by one) or set to 0 if there is no previous member. If specified, the value must be in the range of the enum’s underlying type. Values can be specified for some members only, and multiple members can have the same value.

Note

When updating a database from a model (Model-First approach), for an entity with a property whose type is set to Enum, the database column type is assigned based on the enum’s underlying type.

Adding a new enum type to a model

To add a new enum type to a model:

1. In the Model Explorer window, right-click the Enum Types node and select New Enum Type from the context menu.

Alternatively, click the New Enum Type button on the toolbar of the Model Explorer or Model toolbar, or press ALT+N.

The Enum Type Editor dialog is displayed:

Enum Type Editor dialog

2. In the Name box, enter the name of the enum type. If this is an external enum, enter the full name including the namespace.

3. From the Access dropdown list, select either Public or Internal.

4. From the Underlying Type dropdown list, select the required underlying type.

5. Optional: To indicate that the enum type can be treated as a set of flags, select the Is Flag checkbox.

6. Optional: To indicate that the enum type is external and should not be generated by Entity Developer, select the Is External checkbox.

7. Optional: In the Members table, specify names and values of the members for the enum type.

8. Click OK.

The newly created enum type appears in the Enum Types node of the Model Explorer. If needed, drag it to the diagram area.

Adding enum type members

To add a member to an existing enum type:

  1. In the Model Explorer window or on the diagram surface, right-click the required enum type.
  2. From the shortcut menu, select New Member.

A new member with default properties is added to the selected enum type.

Modifying existing enum types

To modify an enum type:

  1. In the Model Explorer window or on the diagram surface, double-click the required enum type.
  2. In the Enum Type Editor dialog, change one or more parameters as needed.
  3. Click OK.

The selected enum type is successfully modified.

Deleting existing enum types

To delete an existing enum type, use one of these options:

  • To delete only from the diagram, select it and press SHIFT+DELETE.
  • Right-click the required enum type on the diagram or in the Model Explorer and select Delete from the context menu, or select the enum type and press DELETE.

Entity Developer will ask whether you want to delete the object from the model as well.

Warning when deleting used enums

If the enum type is assigned as the type of a property in the model, a warning dialog is displayed after confirmation:

Enum Delete Warning

Use this dialog to select the appropriate action.

External enums

Entity Developer can work with external enums. These are enums already defined in your project that should not be generated by Entity Developer.

For external enums:

  • You can omit member definition.
  • Enter the full name including the namespace containing the enum.
  • Select the Is External checkbox in its editor, or set its Is External property value to True in the Properties window.

See also

  • Working with classes
  • Working with properties