ManyToManyLookupEdit
The ManyToManyLookupEdit component provides an inline autocomplete editor for managing many-to-many (N:N) relationships between Dataverse records. It displays the currently associated records as chips and allows users to search, add, and remove associations without navigating away from the form.
How It Works
Place the component inside a RecordContext and specify the RelationshipName. The component automatically resolves the related table, loads associated records, and provides a searchable autocomplete dropdown for adding new associations.
<RecordContext TableName="account" QueryParameterName="id">
<ManyToManyLookupEdit RelationshipName="ppp_Account_ppp_Region_ppp_Region" />
</RecordContext>
Views
Use ViewIds and DefaultViewId to control which views are available for searching related records. The view's columns are displayed in the dropdown to help users identify the correct record. If no views are specified, the default public view for the related table is used.
<ManyToManyLookupEdit RelationshipName="ppp_Account_ppp_Region_ppp_Region"
ViewIds="_regionViews"
DefaultViewId="@(new Guid("..."))" />
@code {
private List<Guid> _regionViews = new List<Guid>
{
new Guid("..."),
new Guid("..."),
};
}
Validation
Use MinimumNumberOfItems and MaximumNumberOfItems to enforce constraints on the number of associated records. Setting a minimum automatically marks the field as required.
<ManyToManyLookupEdit RelationshipName="ppp_Account_ppp_Region_ppp_Region"
MinimumNumberOfItems="1"
MaximumNumberOfItems="3" />
Saving
Changes are tracked as pending associate and disassociate requests. When the parent MainContext is saved, these requests are included in the transactional save operation alongside any other record changes.
<MainContext>
<MenuBar>
<SaveContextButton />
</MenuBar>
<RecordContext TableName="account" QueryParameterName="id">
<ColumnEdit ColumnName="name" />
<ManyToManyLookupEdit RelationshipName="ppp_Account_ppp_Region_ppp_Region"
MinimumNumberOfItems="1"
MaximumNumberOfItems="3" />
</RecordContext>
</MainContext>
Example
The following example shows a basic ManyToManyLookupEdit bound to a many-to-many relationship.
Configuration Options
Use the controls below to explore the ReadOnly, Disabled, MinimumNumberOfItems, and MaximumNumberOfItems properties.
ManyToManyLookupEdit Class
Parameters
Name | Type | Default | Description |
|---|---|---|---|
ChildContent | RenderFragment? | Child content of the component | |
Context | MainContext? | Cascading context that registers this editor for coordinated save operations. | |
DefaultViewId | Guid? | Specifies which view should be used as the default when browsing related records. | |
Description | string? | Description to be displayed in the tooltip. | |
Disabled | bool? | Should the editor be disabled. | |
DisplayLabelWhenAvailable | bool | True | Specifies whether to display a lable if available. |
DisplayTooltipWhenAvailable | bool | True | Specifies whether to display a tooltip if available. |
DisplayValidationErrorMessage | bool | True | Should a validation error message be displayed when the component fails validation? |
IsDirty | bool | False | Gets a value indicating whether there are pending association or disassociation changes that have not yet been saved. |
IsVisible | bool | True | Is the editor visible. |
Label | string? | Text to be displayed as a label for the editor. | |
MaximumNumberOfItems | int? | Maximum number of related records that may be selected. | |
MaxRecordsReturned | int | 20 | Maximum number of records returned from Dataverse when searching for related records. |
MinimumNumberOfItems | int? | Minimum number of related records that must be selected for the editor to be considered valid. | |
ReadOnly | bool? | Should the editor be read-only. | |
RelationshipName* | string | The Dataverse many-to-many relationship name that this editor manages. | |
Required | bool? | Should the value be required. | |
ViewIds | List<Guid>? | Limits which views are available for browsing related records; if empty, the default public view is used. |
ChildContentContextDefaultViewIdDescriptionDisabledDisplayLabelWhenAvailableDisplayTooltipWhenAvailableDisplayValidationErrorMessageIsDirtyIsVisibleLabelMaximumNumberOfItemsMaxRecordsReturnedMinimumNumberOfItemsReadOnlyRelationshipName*RequiredViewIdsMethods
Name | Parameters | Type | Description |
|---|---|---|---|
GetRequests | List<OrganizationRequest> | Returns the pending Requests.OrganizationRequest operations (associate and disassociate) that must be executed to persist the current selection. | |
GetValidationErrors | List<string> | Returns validation errors for the current selection, including violations of minimum and maximum item count rules. | |
RefreshAsync | bool forceRefresh | Task | Instructs the grid to re-fetch and render the current data from the supplied data source. |
ResetState | void | Clears all pending association and disassociation changes, resetting the editor to its last saved state. | |
Validate | bool | Returns |
GetRequestsRequests.OrganizationRequest operations (associate and disassociate) that must be executed to persist the current selection.GetValidationErrorsRefreshAsyncResetStateValidate