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.

ValueEffect
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'".
IsolatedAllows the master delete and leaves orphans.
CascadingDeletes 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 WinFormBlockHost controls inside one WinFormFormHost. The detail cascades as the master record changes.
  • WPF: a BeepWpfForms host shows one active block, so use one host for the master and one for the detail when both must be visible. Call SyncFromManager() on the detail block when needed.