Entity/Model Designer

This section introduces available options in the Entity Designer and Model Designer:

  • Entity Designer: The designer opens after you select the “Entity design” in the New Item. It allows you to create and configure an entity that is compatible with EF Core, SQLSugar, Dapper, or other ORMs. (Currently, only EF Core 6 is supported). Normally for each table, you create one entity.

  • Model Designer: The designer opens after you select the “Model design” in the New Item. It allows you to create and configure models according to your business logics. The model can be used to represent data or groups of data from different entities or external APIs, or update data to the database through entities.

Entity Designer and Model Designer have similar options; the shared options will be described below without mentioning which designer it belongs to, unless otherwise if the option is available in only Entity Designer or Model Designer.

Field Design

Entity/Model-level settings

Entity/Model: The name of the entity/model.

Display name: The display name of the entity/model. The [DisplayName] model attribute will be generated in the C# code.

Description: The description of the entity/model. The description will be displayed as a comment in the C# code.

Base class: Choose whether to inherit from another entity/model. When a base class is selected, and the Show base class option is checked, the fields of the base class will be displayed as read-only below the current field list.

Queryable/Creatable/Updatable/Deletable: The entity/model can be configured to generate Basic APIs (including Get, GetList, GetPage, Create, Update, Delete). To do that, select the check box of Queryable, Creatable, Updatable, and Deletable on the entity/model level. (You can also select which fields will be included in the query/create/update models.)

Storage

(The following options are only available for entity)

Table: The database table to which the entity is mapped. Usually each entity needs to map with a data table. If no table name is specified here, the entity class name will be used as the table name.

Schema name: If using a relational database, you will also need to specify the table schema. If no schema name is specified here, the default schema in the database will be used.

When the storage options are set, the following C# code will be generated:

Field-level settings

Field color

Purple: The data type of this field is set to Compute.

Green: The data type of this field is set to Entity type which makes reference to the other entity.

Blue: The data type of this field is set to Enum type which makes reference to the enumeration file.

White: The field is inherited from the base class.

Basic

Field: The name of the field.

Display name: The display name of the field. The [DisplayName] model attribute will be generated in the C# code.

Description: The description of the field, which appears as a comment in the C# code.

Data type: The data type of the field. For example, the Int32 data type will be defined as the int type in the C# code.

If the Compute data type is selected, an expression will be required.

The following C# code will be generated:

Collection

When the Collection option is selected, it means the current field will be converted to a collection type, for example: List.

When Collection is not selected, the following C# code will be generated:

public DateTime DateTime { get; set; }

When Collection is selected, the following C# code will be generated:

 public List<DateTime> DateTime { get; set; } = new();

In addition, when Collection is selected, the Conversion option below will be automatically selected as CollectionToStringConverter. The following C# code will be automatically generated, indicating that the current collection field (property) has been configured for value conversion (a collection field defined on an entity cannot be directly stored in the database, and a value converter must be used for data conversion before it can be stored. For example, a string collection List has the values str1, str2, str3, and the value converter determines how it will be converted into a string and stored in the database, for example, concatenated into str1;str2;str3 using the ; symbol).

Nullable

When the Nullable option is selected, the field will allow to have a null value. For example, when a field of boolean type is selected to be nullable, the data type of the field will be defined as bool?, and the field can have three values: true, false and null.

Queryable

The Queryable option for a field is selectable only when the Queryable option for the entity is selected.

The Queryable option for the entity determines whether the Get, GetList, and GetPage APIs will be available in the API Design tab. The Queryable option for the entity is only available when the entity is configured with a Key.

The Queryable option for a field determines whether the field will be included in the query model.

If you have selected the check box of Queryable for one or more fields, these fields will be included in the query model.

The following C# code will be generated:

Creatable

The Creatable option for a field is selectable only when the Creatable option for the entity is selected.

The Creatable option for the entity determines whether the Create API will be available in the API Design tab.

The Creatable option for a field determines whether the field will be included in the create model.

If you have selected the check box of Creatable for one or more fields, these fields will be included in the create model.

Updatable

The Updatable option for a field is selectable only when the Updatable option for the entity is selected.

The Updatable option for the entity determines whether the Update API will be available in the API Design tab.

The Updatable option for a field determines whether the field will be included in the update model.

If you have selected the check box of Updatable for one or more fields, these fields will be included in the update model.

Deletable

The Deletable option for the entity determines whether the Delete API will be available in the API Design tab. Once the Delete API is available and generated, data records will be deletable automatically.

Validation

Required: Whether to make the current field a required field. After the Is required option is selected, you can specify the message displayed when the validation fails. When Is required is selected, the [Required] model attribute will be generated in the C# code.

Regular validation: Click to expand the Regular validation input box, you can manually input the expression used to validate the data or select a system predefined expression from the Common regular expressions list (for example, DateTime, Domain, Email, IP address, Password, etc.). After selecting a predefined expression, you can also modify the predefined expression according to your needs. When the Regular validation option is specified, the [RegularExpression] model feature will be generated.

Regular validation error: The message that will be displayed when regular validation fails.

When the validation options are set, the following C# code will be generated:

Data

Default value (only available for entity): Specifies the default value of the database column. If the inserted row does not have a value for that column, the default value will be used. There are three ways to specify the default value: 1) Enter the default value manually; 2) Calculate the default value through an expression; 3) Set the default value through an SQL statement.

Cascading updates: When the current field is associated with another entity, this option is available for selection. (To associate a field with an entity, you click the data type list and then select Entity > [entity].) After a field is associated with an entity and the Cascading updates option is selected, data will be updated to the entity directly once there are data updates.

When a field is associated with an entity, foreign keys will be created when the database table is generated. The Cascading updates option here works in the same way as the cascade update in the database.

Note: When selecting Cascading updates, please also select the Updatable option, as well as the Create page, Edit page and Detail page in the View Settings page to ensure that no error occurs when the master data is loaded into the frontend application.

When Cascading updates is not selected, the following C# code will be generated:

When Cascading updates is selected, the following C# code will be generated:

Read from (only available for model): reads data from an entity.

Write to (only available for model): writes data to an entity.

Read and write can be set separately (if read is not set, data can be passed in from the interface, and then written to the entity fields through write).

(The business model has not yet implemented the API and code generation functions for read and write).

Data range

Some data types (such as String, Single, Double, Decimal) have the following options:

Minimum length: Specifies the minimum length of the string field, or the minimum value of the numeric field.

Maximum length: Specifies the maximum length of the string field, or the maximum value of the numeric field.

Length error: The message that will be displayed when the length/range is invalid.

When these options are specified, the corresponding type of model attribute will be generated in the C# code, for example, when the field type is string, the [StringLength] attribute will be generated.

For example, when the field type is int32 (or single, double, decimal), the [range] attribute will be generated.

[Range(2, 4, ErrorMessage = "Length must be between 2 and 4.")]

EF Core 6

(Only available for entity)

The options under the EF Core 6 section will be used to generate and configure the corresponding properties in the entity (what are called fields here are called properties in EF Core).

For example, the Key option when checked will generate the [key] model attribute for the current field. For most options, we will generate attributes (also known as data annotations) to represent the configuration, for some special options such as Key, Index, we will generate fluent APIs to represent the configuration. The fluent API configuration takes precedence over the attributes.

Do not save in the database: Whether or not to include this field in the database. If checked, a [NotMapped] model attribute will be generated in the C# code, indicating that this field is excluded from the database table.

Key: Specify the field as the primary key and specify the key name. When this option is selected, the [key] model attribute will be generated in the C# code, indicating that the current field is the primary key.

For example, the following code indicates that the current field is used as the entity’s primary key and named as keyname1.

Column name: Specify the column name in the data table. The entity property will be mapped to this column.

Column type: Specifies the column type in the data table.

When Column name and Column type are specified, the [Column] model attribute will be generated in the C# code. For example: in the following code, the Password property is mapped to the col1 column, and the column type is specified as character type.

Set concurrency check: Specifies whether the data column performs concurrency conflict checking to implement optimistic concurrency control. When this option is checked, the [ConcurrencyCheck] model attribute will be generated in the C# code.

Set index: Specifies whether the data column is used as index.

Uniqueness validation: Specifies whether to perform uniqueness validation on the index. This option is selectable only when Set index is selected.

When Set Index and Uniqueness validation are selected, the following HasIndex and IsUnique methods will be generated in the C# code, indicating that the current field is set as a unique index.

(Entity only) When a field is associated with an entity, the following three options are available

Required: When this option is selected, it indicates that the field is required. After the Required option is selected, you can specify the message displayed when the validation fails. When the Required option is selected, the [Required] model attribute will be generated in the C# code.

Inverse navigation property: Selects a field as the inverse navigation property. The [InverseProperty] model attribute will be generated in the C# code.

        [InverseProperty("PurchaseAsset")]
        public AssetPurchaseItem Category { get; set; }

Deletion strategy: An OnDelete method will be generated with the DeleteBehavior parameter supporting the following enum values (Cascade, SetNull, NoAction):

  • Default: A strategy that best suits your business logic will be automatically picked.
  • Cascade Delete: When the parent entity is deleted, the child entity is also deleted.
  • Set null: When the parent entity is deleted, the foreign key values in the child entity are set to null. This option should be selected when the foreign key values can be set to null.
  • No action: When the parent entity is deleted, the child entity is not affected. This option should be selected when the foreign key values cannot be set to null.

The Deletion strategy option is Set null when the Data > Cascading updates option is selected.

(Entity only) When a field is associated with a model, the following options are available

Owned entity: This option is available when the current field is associated with another model. When this option is selected, it means the current field is an owned entity of the parent model type. The OwnsOne method will be generated in the C# code.

Converter: This option is not available when Owned entity is selected. When this option is selected, the default value is CollectionToStringConverter, indicating that the collection field (property) has been configured for value conversion. The HasConversion method will be generated in the C# code.

The generated code is as follows:

Storage

For a numeric type (such as Single, Double, Decimal), the following options are available

Precision: Specify the total number of digits (including integer digits and decimal digits) the database will store.

Scale: Specify the number of decimal places the database will store.

After these two properties are set, the data precision of the data will be generated, for example, decimal(14,2).

For Compute type, the following options are available

Data type: Specifies the data type.

Compute value: Specifies the expression.

(Entity only) For Enum type, the following options are available

Conversion: Currently only EnumToStringConverter is available, which indicates that the enum values will be converted to strings in the database. The HasConversion method will be generated in the C# code.

The generated code is as follows:

Condition Design

When a condition is created, and if you select to generate the Conditions APIs in the API Design tab and select the condition in the View Settings tab, the corresponding condition model (data), service (interface and business logic), controller (invoking methods), and Vue file (frontend pages) will be generated.

For example, a condition like below indicates that data which is smaller than the user input value will be searched and displayed. (It is supposed to be greater than, but there is a bug here).

Condition Model (data)

Service (interface and business logic) (make sure the Conditions APIs in the API Design tab have the Generate option selected.)

Controller (invoking methods)

Vue file (display on the frontend app) (make sure the condition is selected in View Settings tab)

Field: Select the field of the entity, for example Name = A.

Expression : Enter a conditional expression, such as Length(name) > A.

Match: For fuzzy search. User-entered values can be matched against multiple data columns. For example, if you want to query employees whose name or alias contains the letter A: “name like A or alias like A”, you can create a match and add two fields: 1) name contains A; 2) alias contains A; and connect these two fields with OR.

Scope: Sets priority if there are multiple conditions. For example, to query females with age greater than 20 or males with age greater than 30: “(Age > 20 and gender = female) or (Age > 30 and gender = male)”. The bracket part needs to be implemented through scope, and the code generated by the bracket part will be evaluated as one set of conditions.

Query Order: Sets the sorting rules of the search results.

Query Group: Sets the grouping rules of the search results. (Not available yet)

Required: Whether it is required.

If Required is selected, the [Required] attribute is generated in the C# code.

Readonly: Specifies whether the condition is readonly. If both the search criteria and the search value are determined (which means there is no need for end users to input any value), then you can set this condition to readonly and set a default value for the condition.

For example, to search for resigned employees, you can set the condition to readonly and set the default value of WorkState to not equal to EmployeeState.Quit:

If Readonly is selected, then only get method will be generated.

If Readonly is not selected, both get and set methods will be generated.

API Design

Whether to generate the controller and service for the basic APIs and condition APIs.

Basic APIs are available if you have selected the check box of Queryable, Creatable, Updatable, and Deletable on the entity level in the Field Design tab. Basic APIs include: Get, GetList, GetPage, Create, Update, and Delete.

Condition APIs are available if you have created a condition in the Condition Design tab. Each condition will have three APIs: GetPage, Update, and Delete.

Generate: Generates the interface and implementation in the service file and the invoking method in the controller file.

Authorize: After selecting this option, enter the name of the authorization policy. During the authorization process, the permission settings under the specified policy will be validated (the user needs to code and implement the policy separately).

For example, if you have selected the check box of Generate for the Update API, the corresponding interface and implementation will be generated in the service file and the invoking method will be generated in the controller file.

Code generated in the service:

Code generated in the controller:

View Settings

The View Settings determines which fields will be displayed in the app pages (such as the list page, add page, edit page and details page). Currently, the app pages are pre-defined (with only one UI theme) and cannot be previewed during the design time.

View-level settings

Condition (List): Select a condition. The condition will be displayed in the List page. The conditions that you created in the Condition Design page will be available for selection.

Display Type (Create) / Display Type (Update) / Display Type (Details): Select a display type for the New, Edit, or Details page.

  • Dialog: The page will be displayed as a dialog.
  • Drawer: The page will be displayed as a drawer.
  • Page: The page will be displayed as a normal page. (This display type is unsupported in the preview version)

Field-level settings

Readonly: Specifies whether the current field is read-only in the Edit page and New page. It can be set separately in the Edit page and New page.

Display type: Selects one of the built-in display styles. Depending on the field type, the display types are different.

For example, for numeric fields, the display type can be Default, Progress, Rate.

For boolean fields, the display type can be Default, CheckBox, Switch.

For text fields, the display type can be Default, Link, Tag, Image, Password, Email, Phone Number, HTML, Multi-line text.

If the field is associated with an Enum, the display type can be Default, Option, Select from dropdown.

Display format: Specifies a custom display format, such as yyyy-mm-dd.

List page

Whether the field will be shown on the list page of the frontend app.

For example, if you have selected the check box of List page for the following fields, they will be shown on the list page of the application.

New page

Whether the field will be shown on the new page of the frontend app.

For example, if you have selected the check box of New page for the following fields, they will be shown on the Add page of the application.

Edit page

Whether the field will be shown on the edit page of the frontend app.

For example, if you have selected the check box of Edit page for the following fields, they will be shown on the Edit page of the application.

Details page

Whether the field will be shown on the details page of the frontend app.

For example, if you have selected the check box of Details page for the following fields,

they will be shown on the Detail page of the application.

Dependency/Expression/Computed fields overview

By clicking the bar in the lower left corner of Entity/Model Designer, you can have a view of all of the dependencies, expressions, and computed fields used in the current entity or model.