namespace After;
// ---------------------------------------------------------------------------
// The persistence side of the "after" situation. The (fake) framework stores
// its own data-only records — / ,
// both subclasses — never the domain objects themselves.
// Domain state reaches storage only through explicit mapping; the context keeps
// a reference-identity map so a second of the same domain
// object refreshes its row instead of duplicating it.
// ---------------------------------------------------------------------------
///
/// Persisted shape of a : data only — the orders are
/// separate rows, so nothing more is needed here.
///
public sealed class ClientData : DbBase
{
/// Display name of the client.
public string Name { get; set; } = string.Empty;
}
///
/// Persisted shape of an : data only. The object graph is
/// flattened for storage — the back-reference to the client becomes a foreign
/// key, because storage has ids, not object references.
///
public sealed class OrderData : DbBase
{
/// Free-text description of what this order is for.
public string Description { get; set; } = string.Empty;
/// Order total in cents of the stored order.
public int TotalInCents { get; set; }
///
/// Foreign key to the owning client: when the
/// order has no client, or when its client had no id yet at save time —
/// save clients before their orders.
///
public Guid ClientId { get; set; }
}
///
/// The fake DbContext: per-type tables of data records, mirroring EF
/// Core's Set<T>. /
/// map the domain object's *current* state into its record — inserting on the
/// first save, refreshing in place on later ones.
///
public class DbContext
{
// ── per-type data tables ─────────────────────────────────────────
private readonly List _clients = new();
private readonly List _orders = new();
// ── fast lookup: domain object reference → its persisted record ──
private readonly Dictionary