using System.Collections.ObjectModel; namespace After; /// /// A plain domain object — the "after" shape of the exercise: no /// inheritance, no knowledge of . /// Its data travels to the WebApp as a ; persisting it /// is an explicit act of the context, not an inherited capability. /// public class Client { /// /// Primary key as a plain value: fresh objects have /// until a explicitly /// saves them (which copies a generated id in). A plain field — it is not /// a persistence concept leaking into the domain. /// public Guid Id { get; set; } /// Display name of the client. public string Name { get; set; } = string.Empty; /// /// Navigation collection of this client's orders, with EF-style /// navigation fix-up (see ). /// public ClientOrders Orders { get; } public Client() { Orders = new ClientOrders(this); } } /// /// An collection that fakes EF's navigation fix-up: when an /// order is added, its back-reference is set to the /// owning client, exactly as EF would wire up the two ends of the relation. /// public sealed class ClientOrders : Collection { private readonly Client _owner; public ClientOrders(Client owner) { _owner = owner; } // Both Add(...) and Insert(...) funnel through InsertItem, so overriding // it covers every way an order can be added to the collection. protected override void InsertItem(int index, Order item) { ArgumentNullException.ThrowIfNull(item); item.Client = _owner; // navigation fix-up: order now knows its client base.InsertItem(index, item); } }