Entity Settings

Learn how to enhance your entity

Entity-Level Configuration Options

In addition to defining individual Properties for your entity, BlazorForKids allows you to configure several important behaviors directly at the entity level. These settings control how your entity is displayed, queried, stored, and secured. Below are the most important configuration methods you can use in the designer object for each entity.


1. DefaultCatalogTextProperty

When you use this method, you're defining the default text that will be shown in any dropdowns or selectors that display this entity in the UI. This is especially important for user-friendly displays of foreign key relationships.

Example:

designer.DefaultCatalogTextProperty(a => $"{a.FirstName} {a.LastName}");

This tells the framework to display the employee’s full name (first + last) as the label whenever this entity appears in a select input, a related entity reference, or a catalog-like UI element.


2. DefaultOrderBy

This method defines the default property used for sorting when records of this entity are displayed in lists or grids. Without this, records may appear in random order depending on the database engine.

designer.DefaultOrderBy<string>(a => a.FirstName);

In this example, employees will be sorted alphabetically by their FirstName in grid views, selects, and other data-bound lists.


3. HasIndex

Defining indexes is critical for improving performance when querying or filtering entities. You can define one or more indexes using the HasIndex method, with optional support for unique constraints and filter conditions.

designer.HasIndex(a => a.Email, true);

This creates a unique index on the Email property, ensuring each value is unique and improving lookup performance. You can also define standard indexes:

designer.HasIndex(a => a.FirstName);

Indexes can also be filtered by supplying an optional filter expression as a string.


4. EntityDisplayInfo

This method lets you specify a friendly name and optional description for the entity. This label is used in UI components like headers, page titles, tooltips, or documentation.

designer.EntityDisplayInfo("Employee", "Employees are the people who work for the company");

It helps both developers and users quickly understand the purpose of the entity.


5. HasTemporalTable (SQL Server only)

Temporal tables are a SQL Server feature that allow automatic tracking of changes to rows over time. By calling this method, you instruct the framework to configure the entity's table as a temporal table, enabling history tracking and audit capabilities without custom logic.

designer.HasTemporalTable();

You can optionally specify a custom name for the history table:

designer.HasTemporalTable("EmployeeHistory");

Important: This feature only works when using SQL Server as your database provider.


6. Authorization Rules (Role-Based Security)

The designer.Authorization property gives you full control over which user roles can create, read, update, or delete records of the current entity. This is a powerful way to enforce business rules directly at the data model level.

Example:


designer.Authorization.RestrictDeleteToRoles(["Admin", "Manager"], "You are not allowed to delete this employee");

Available restrictions include:

  • RestrictCreateToRoles(string[] roles, string message)
  • RestrictReadToRoles(string[] roles, string message)
  • RestrictUpdateToRoles(string[] roles, string message)
  • RestrictDeleteToRoles(string[] roles, string message)

Each restriction allows you to specify which roles are permitted, and a custom message that will be shown if the user does not meet the access criteria.

This feature ensures that your business logic is respected even if someone tries to bypass the UI and make changes directly via API or other tools.


Summary

These entity-level settings allow you to go beyond field definitions and fully configure how your entity behaves inside the application. You can:

  • Control how records are sorted and displayed by default.
  • Improve performance through index creation.
  • Track changes with temporal tables (SQL Server only).
  • Secure your data with role-based access rules.
  • Define intuitive display text for user-friendly dropdowns and selects.

Using these methods gives you fine-grained control over both the behavior and performance of your application, while also improving the user experience and enforcing critical business rules.

An unhandled error has occurred. Reload 🗙