Many To Many Relations
In BlazorForKids, many-to-many relationships — such as assigning employees to multiple teams or associating documents with a job title — are handled using the AddManyEntities<T> method. While the framework does not render direct editors for many-to-many relationships inside the standard form layout, it does provide a specialized editor component for managing these links. As shown in the image, this editor allows users to easily move items between the "available" and "selected" lists using intuitive controls. It's perfect for managing connections between two sets of data.

This approach keeps your main forms clean while still giving users a
clear and powerful way to manage relationships. If you prefer, you can also
create your own custom editor by using any component that implements InputBase<T>
.
This flexibility allows developers to build checkboxes, toggles, or more advanced
UI patterns to edit many-to-many relationships in a way that best fits their application.
All standard configuration options are supported, along with relationship-specific features
like eager loading or default query inclusion.
publicpartialclassEmployee:IBkEntity<Employee,ApplicationDbContext>
{
publicvoidBkConfiguration(IBkEntityDesigner<Employee,ApplicationDbContext>designer)
{
// Note: The AddManyEntities<T> method defines a many-to-many relationship.// In this case, each Employee can be in multiple Teams, and each Team can have multiple Employees. designer.Properties.AddManyEntities<Team>("Teams",c=>
{
// Sets the label text shown next to the checkbox list or multi-selector. c.Label("Teams");
// Specifies the name of the reverse navigation property (Team.Employees).// Needed only if you want the related entity to track the link. c.NameOfMany("Employees");
// Sets the tab order of the editor within the form. c.TabIndex(5);
// Instructs the framework to include the full list of selected Teams when retrieving Employees. c.IncludeToDefaultQuery();
});
}
}
Configuration Options for AddManyEntities<T>
Method | Description | Parameters |
---|---|---|
NameOfMany |
Defines the reverse navigation property name on the related entity.
For example, if an Employee can be in multiple Teams, this would be Team.Employees .
|
string collectionName |
IncludeToDefaultQuery |
Instructs the framework to include the full related collection (e.g., Teams ) when querying the parent entity.
|
None |
Label |
Sets the label displayed next to the multi-selector or checkbox list. | string label |
TabIndex |
Sets the tab order of the editor in the form. | int tabIndex |
ToolTip |
Adds a tooltip that appears when hovering over the input editor. | string tooltip |
CssClass |
Applies a custom CSS class to the checkbox list or selector editor. | string className |
HideEditor |
Hides the editor from the form by default. | None |
HideGridViewColumn |
Hides the column from the grid view. | None |
ValidationRuleValue |
Adds a validation rule based on the selected collection of related entities. | Func<ICollection<T>, bool> rule ,string errorMessage ,string attributeName |
ValidationRuleModel |
Adds a validation rule using the full model (e.g., requiring at least one team for certain roles). | Func<TModel, bool> rule ,string errorMessage ,string attributeName |
ValidationRuleUsingDbContext |
Defines a custom 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 |