ZuloOne
English
Sign in
Menu

Create an enum

Updated

An enum is a closed list of named integers. The column stores the integer. The names live on the enum object. A field reaches it through an EDT with edtType: "Enum" and enumMetaId. Kind: Enum.

Note

An enum is not a Reference and not a scalar Integer you invent on the field. The EDT is the type. The enum is the list of values. Create an EDT covers Reference and scalar only.

How to#

1. The enum — Enums/<Name>.json, kind: "Enum". A new GUID in metaId. modelId is your model's. Names are PascalCase Latin.

Each value has its own metaId, an integer value, a name, and a caption. en is the base. Inventory's PriceTypeKind is the small example: Base = 0, Calculated = 1.

The generated C# enum is non-nullable. Unset equals 0. Give 0 to the working default (String on CharacteristicValueType, Base on PriceTypeKind), not to a rare case the record must opt into.

2. The Enum EDT — EDTs/<Name>Edt.json, kind: "EDT", edtType: "Enum", enumMetaId of the enum. Convention is <Name>Edt (PriceTypeKindEdt). A field cannot point at the enum directly.

3. Use it on a field — edtMetaId of that EDT, not baseType. In a typed script the property is the generated enum:

if (priceType.Kind == PriceTypeKind.Calculated)
    return;
priceType.Kind = PriceTypeKind.Base;

On an information register, an Enum dimension or resource binds as an integer, the same way Integer does. EDTResolver maps the EDT to an integer column. The card widget is a Select; the stored value is the integer.

4. Bump modelVersion in the same change.

Warning

Through REST the value travels by name. Db.UpdateAsync / IDataService write the column as an integer. Passing the name there fails with "Conversion failed when converting the nvarchar value 'VatPayer' to data type int", not "unknown enum value". A read may return either the number or the name — accept both.

When the list is records the tenant will add, use a dictionary and a Reference EDT, not an enum.

What's not there yet#

There is no catalog of every enum. Look in Enums/ of the model.

Where next#

Was this page helpful?