Master detail
Relations, delete behavior and coordination.
In this documentation
- Beep.Forms
- Architecture
- Authoring in the Object Navigator
- WinForms runtime
- WPF runtime
- End-to-end example
- Remote UI limitations
- Overview
- Context menus
- Blocks and items
- Triggers
- Lists of values
- Validation
- Master detail
- Navigation and queries
- Alerts, editors and timers
- Calling other forms
- Form menus
- Hosting in WinForms step by step
- Hosting in WPF step by step
- Saving and loading forms
- The IDE toolbar and dialogs
- Troubleshooting
Creating a relation
manager.CreateMasterDetailRelation("Ord", "OrdLine", "Id", "OrderId");
The arguments are the master block, the detail block, the master key field and the detail foreign key field. An optional fifth argument is the relationship type, OneToMany by default. Another overload takes an array of DataBlockFieldMapping (MasterField, DetailField) for composite keys.
Both blocks must be registered first. Otherwise an InvalidOperationException says "Master block 'X' is not registered" or "Detail block 'X' is not registered".
Working with relations
GetDetailBlocks, GetMasterBlock, GetActiveRelationships(master), SynchronizeDetailBlocksAsync, SynchronizeDeferredDetailAsync, HasPendingDeferredSync and ClearBlockRelationships.
Delete behavior
Set DeleteBehavior on the relationship objects returned by GetActiveRelationships.
| Value | Effect |
|---|---|
NonIsolated (default) | Blocks the master delete while detail records exist. The status text is "Cannot delete: block 'X' has N detail record(s) in 'Y'". |
Isolated | Allows the master delete and leaves orphans. |
Cascading | Deletes the detail records through the detail delete pipeline, then fires OnClearDetails. |
The ON-CHECK-DELETE-MASTER and ON-LOCK triggers fire during a master delete.
Coordination
Coordination on the relationship is Immediate (default) or Deferred. Deferred detail synchronization is run with SynchronizeDeferredDetailAsync.
In the hosts
- WinForms: place sibling
WinFormBlockHostcontrols inside oneWinFormFormHost. The detail cascades as the master record changes. - WPF: a
BeepWpfFormshost shows one active block, so use one host for the master and one for the detail when both must be visible. CallSyncFromManager()on the detail block when needed.