One to Many Property

View Entity One Entity Property Configuration Options

One To Many Relation

When you want to link two entities together — for example, each employee belonging to one department — you can use the AddOneEntity<T> method. This defines a one-to-many relationship, where one record from another table (like Department) is connected to many records in the current table (like Employee). In this setup, each employee is assigned to one department, but each department can have multiple employees. The framework will automatically generate a dropdown in the form, allowing users to choose from the list of related entities. You can also enable a searchable dropdown using UseDropDown for a better user experience with large datasets.

This method supports all the standard property configurations like label, tooltip, visibility, and tab index. In addition, it provides options specific to navigation properties, such as enabling cascade delete (removing related data automatically) and eager loading (loading related data upfront). This feature is especially useful when defining foreign key relationships in your models and helps the framework generate the right form controls, data validation, and access logic. It simplifies working with related data and ensures your UI stays in sync with the database structure.

publicpartialclassEmployee:IBkEntity<Employee,ApplicationDbContext>

{

    publicvoidBkConfiguration(IBkEntityDesigner<Employee,ApplicationDbContext>designer)

    {

// Note: The AddOneEntity<T> method defines a one-to-many relationship.// In this case, each Employee has one Department, and each Department can have many Employees.        designer.Properties.AddOneEntity<Department>("Department",c=>

        {

// Sets the label text displayed next to the dropdown.            c.Label("Department");

// Specifies the name of the collection property on the related entity (Department.Employees).// This is only needed if you want to create a shadow navigation property for reverse access.            c.NameOfMany("Employees");

// Sets the tab order for the editor in the form.            c.TabIndex(4);

// Uses a custom searchable dropdown instead of a standard <select>.// Recommended when the number of related records may be large.            c.UseDropDown();

// Ensures the related entity (Department) is included in default queries.// This allows accessing the full object instead of just the foreign key (Id).            c.IncludeToDefaultQuery();

// Marks the relationship as optional, allowing the foreign key to be nullable.            c.IsOptional();

// Enables cascade delete: when the Department is deleted, its related Employees will also be deleted.// Use with caution.            c.AllowCascadeDelete();

        });

    }

}


Configuration Options for AddOneEntity<T>

Method Description Parameters
NameOfMany Specifies the name of the reverse navigation property (e.g., Department.Employees) on the related entity. Required only if a shadow property is needed for reverse access. string collectionName
UseDropDown Enables a searchable and optimized dropdown editor instead of the default HTML <select>. Recommended when the related entity has many records. None
IncludeToDefaultQuery Instructs the framework to eagerly load the full related entity when retrieving data (instead of just the foreign key ID). None
IsOptional Marks the foreign key as nullable, allowing no selection in the UI. None
AllowCascadeDelete Configures database-level cascade delete: deleting the related entity (e.g., Department) will also delete all dependent entities (e.g., Employees). Use with caution. None
Label Sets the label displayed next to the navigation property editor. string label
TabIndex Sets the editor’s position in the form's tab order. int tabIndex
ToolTip Adds a tooltip that appears when hovering over the dropdown. string tooltip
CssClass Applies a custom CSS class to the dropdown for styling. string className
HideEditor Hides the editor from the form by default. None
HideGridViewColumn Hides the property column from the grid view. None
ValidationRuleValue Adds a custom validation rule using the selected entity (e.g., Department). Func<T, bool> rule,
string errorMessage,
string attributeName
ValidationRuleModel Adds a validation rule using the full model. Func<TModel, bool> rule,
string errorMessage,
string attributeName
ValidationRuleUsingDbContext Applies a validation rule using both the database context and the model. Func<DbContext, TModel, bool> rule,
string errorMessage,
string attributeName
ValidationRuleUsingExistingAttribute Applies a built-in .NET validation attribute, such as RequiredAttribute. ValidationAttribute attribute
An unhandled error has occurred. Reload 🗙