using Domain; namespace Db; /// Hand-written mappers between domain objects and persistence records; each method maps one direction and never mutates its input. public static class DataMappers { /// Map a to its persistence record . public static ClientData ToClientData(Client client) { ArgumentNullException.ThrowIfNull(client); return new ClientData { Id = client.Id, Name = client.Name }; } /// Map an to its persistence record ; the client back-reference becomes a foreign key. public static OrderData ToOrderData(Order order) { ArgumentNullException.ThrowIfNull(order); return new OrderData { Id = order.Id, Description = order.Description, TotalInCents = order.TotalInCents.Cents, // value object → plain int for the row ClientId = order.Client?.Id ?? Guid.Empty, }; } /// Map a record back to a . public static Client FromClientData(ClientData row) { ArgumentNullException.ThrowIfNull(row); return new Client { Id = row.Id, Name = row.Name }; } /// Map an record back to an ; the context reassembles the graph. public static Order FromOrderData(OrderData row) { ArgumentNullException.ThrowIfNull(row); return new Order { Id = row.Id, Description = row.Description, TotalInCents = OrderMoney.From(row.TotalInCents), // plain int from the row → value object }; } }