7 Embedded data
Embedded objects are owned values. They are stored inside the parent node, have no identity in the graph, and are deleted with it. Use them for data that only makes sense with its parent: opening hours on a venue, line items on an order, price tiers on an event.
An embedded class is part of the model, so register it with your node types
(§12): AddNamespace picks it up, Add<T> on the parent
does not. On an interface, declare embedded properties getter-only; the store creates the collection.
On a class, initialise them: declare an Embedded<T> getter-only, { get; } = [];, which the store
fills, and an EmbeddedMap with a setter, { get; set; } = [];. There are two kinds.
- Embedded<T> — a collection keyed by the embedded object's own Guid Id — IncludeTypes says which types the collection takes. The default, ThisTypeAndDescending, takes PriceTier and its subclasses; ThisTypeOnly and DescendingTypesOnly narrow that.
- EmbeddedMap<TKey, TValue> — a collection keyed by a property of the value — KeyProperty names the property that holds the key. It must be declared on the closest common base of the allowed value types, and its type must be TKey; the model builder checks both. To key by the value's id instead…
- Working with an embedded map