What you'll learn

This article shows how to model domain data so that useful distinctions and precision survive storage. It applies the idea to names, rates, addresses, audit records, and loyalty points, then derives display values and balances from the stored facts.

Storing data in its richest form is a domain-driven design (DDD) modeling guideline: preserve the source facts and distinctions that the domain needs, rather than storing only a formatted or derived value. A model can derive a simpler value when it retains the required facts and rules; it cannot reliably recover distinctions that were discarded.

The examples use Value Objects and entity design to preserve domain-relevant data. Choose the fields to match the facts your application actually receives and the rules it must support.

Why it matters

A Full Name Does Not Preserve Name Parts

Consider how a team stores a person's name for a Customer entity:

C#


public class Customer
{
    public Guid Id { get; private set; }
    public string FullName { get; private set; }  // "Abdul Rahman"
}
            

A single string cannot answer queries about name parts unless the application retained those parts separately. Splitting on spaces is unreliable: a name can contain multiple given or family names, or follow a different naming convention. Do not infer fields by splitting a display name.

If the source supplied separate name fields and the model collapsed them, that distinction is lost. If the source supplied only a display name, the model cannot safely invent the missing boundaries.

The Percentage Trap

Here is a subtler case found in discount or tax calculations:

C#


public class Discount
{
    // Stored as a pre-divided percentage, e.g. 0.3333...
    public decimal Rate { get; set; }  // ❌ mutable, no validation

    public decimal Apply(decimal amount) => amount * Rate;
}

// Usage
var discount = new Discount { Rate = 1m / 3m }; // 0.3333333333...
            

The original intent was "one-third". Once you store it as a decimal, the fraction 1/3 cannot be represented exactly as a finite decimal. Repeated operations can carry that approximation forward:

C#


// Illustrative: multi-step rounding compounds the error
decimal rate = 1m / 3m;               // 0.3333333333333333333333333333
decimal partialTax = rate * 100m;      // 33.333333333333333333333333330
decimal fullTax = partialTax * 3m;     // 99.999999999999999999999999990
// ≠ 100.00 — and the original fraction is gone forever
            

The example shows how the stored decimal approximation affects later arithmetic. The impact depends on the calculation and its rounding policy; retaining the numerator and denominator preserves the original rate, while monetary results still need an explicit rounding rule.

The Formatted Address Problem

Addresses are another common offender:

C#


public class Order
{
    public string ShippingAddress { get; private set; }
    // Stored as: "14 Baker Street, London, NW1 6XE, United Kingdom"
}
            

One day the logistics system needs to group shipments by city. Another day the tax engine needs the country code. Extracting those values from a formatted address requires fragile, region-specific parsing.

Unstructured Audit Messages Are Hard to Query

A team logs changes as human-readable sentences:

C#


public class AuditEntry
{
    public string Message { get; private set; }
    // "Admin updated subscription price from £49 to £79 on 2026-03-01"
}
            

A display string is difficult to query reliably. To find price changes greater than £20 in Q1 2026, the application would have to parse the message and account for variations in wording, dates, and currency.

The Loyalty Points Balance Trap

Consider a Customer entity in a loyalty programme with two business use cases:

C#


public class Customer : Entity
{
    public LoyaltyPoints Points { get; private set; } = LoyaltyPoints.Zero;

    // Earn points when a customer places an order.
    public void AddLoyaltyPoints(LoyaltyPoints points)
    {
        Points += points;
    }

    // Redemption is allowed only when the current balance is at least 250.
    public void RedeemLoyaltyPoints(LoyaltyPoints points)
    {
        // This sketch assumes comparisons between LoyaltyPoints and integer thresholds.
        if (Points < 250 || points > Points)
            throw new InvalidOperationException("The customer cannot redeem this amount.");

        Points -= points;
    }
}
            

A later order adjustment may require removing points earned for that order, even when the customer's current balance is below 250. Reusing the redemption operation applies the wrong rule; passing a negative amount violates the value object's non-negative invariant. An unqualified subtract method also hides whether the change represents an order adjustment or a redemption.

  • Reuse RedeemLoyaltyPoints, but it applies the redemption eligibility rule.
  • Pass a negative value to AddLoyaltyPoints—but LoyaltyPoints cannot be negative by business rule. Allowing it here violates the always-valid domain model principle.
  • Add a generic SubtractLoyaltyPoints method without the redemption guard, but its name does not express which business operation it represents.

A single balance also hides the distinction between points earned and points redeemed. Those facts have different sources and validation rules, so a balance alone cannot answer questions about either total.

The model should preserve distinctions that arrive from its input or that its business rules need. Value Objects and explicit entity operations help represent those distinctions without assuming that every input already contains more detail than it does.

Implementation

Step 1: Replace Full Name with a PersonName Value Object

When the domain receives given and family names as separate facts, represent those fields directly. Do not use this shape for a domain that receives only an unstructured display name.

C#


public record PersonName
{
    public string First { get; }
    public string Last { get; }

    // Derive the full name on-demand, never store it
    public string Full => $"{First} {Last}";

    private PersonName(string first, string last)
    {
        if (string.IsNullOrWhiteSpace(first))
            throw new ArgumentException("First name is required.", nameof(first));

        if (string.IsNullOrWhiteSpace(last))
            throw new ArgumentException("Last name is required.", nameof(last));

        First = first.Trim();
        Last = last.Trim();
    }

    public static PersonName Of(string first, string last) =>
        new(first, last);
}
            

The entity stores PersonName, not a string:

C#


public class Customer
{
    public Guid Id { get; private set; }
    public PersonName Name { get; private set; }

    public static Customer Register(string firstName, string lastName) =>
        new() { Id = Guid.NewGuid(), Name = PersonName.Of(firstName, lastName) };
}

// Usage
var customer = Customer.Register("Abdul", "Rahman");

Console.WriteLine(customer.Name.First);  // Abdul
Console.WriteLine(customer.Name.Last);   // Rahman
Console.WriteLine(customer.Name.Full);   // Abdul Rahman
            

Full is a display convenience derived from the two fields. Real name formats vary, so use a formatter that matches the domain's requirements rather than treating this concatenation as a universal name format.

The get-only properties cannot be changed through a with expression. Create a new PersonName with PersonName.Of(...) when the name changes.

A basic EF Core owned-type mapping can configure separate columns with OwnsOne. Verify the generated migration and materialization with your EF Core version and database provider:

C#


protected override void OnModelCreating(ModelBuilder modelBuilder)
{
    modelBuilder.Entity<Customer>().OwnsOne(c => c.Name, name =>
    {
        name.Property(n => n.First).HasColumnName("FirstName").HasMaxLength(100);
        name.Property(n => n.Last).HasColumnName("LastName").HasMaxLength(100);
    });
}
            

Step 2: Replace Decimal Rate with a Fraction Value Object

Instead of pre-dividing a fraction into a decimal, store the numerator and denominator:

C#


public record Fraction
{
    public int Numerator { get; }
    public int Denominator { get; }

    // Derive the decimal representation only when needed
    // The constructor ensures the denominator is positive.
    public decimal AsDecimal =>
        (decimal)Numerator / Denominator;

    private Fraction(int numerator, int denominator)
    {
        if (denominator <= 0)
            throw new ArgumentOutOfRangeException(
                nameof(denominator), "Denominator must be positive.");

        // This Fraction models a proportion (0 <= n <= d), not a general rational number.
        // e.g. Fraction.Of(1, 3) = valid discount rate; Fraction.Of(4, 3) = invalid (> 100%).
        if (numerator < 0 || numerator > denominator)
            throw new ArgumentException(
                "Numerator must be between 0 and the denominator.", nameof(numerator));

        Numerator = numerator;
        Denominator = denominator;
    }

    public static Fraction Of(int numerator, int denominator) =>
        new(numerator, denominator);

    public static Fraction OneThird => new(1, 3);
    public static Fraction OneQuarter => new(1, 4);
    public static Fraction Half => new(1, 2);

    public override string ToString() => $"{Numerator}/{Denominator}";
}
            

The Discount retains the exact numerator and denominator. It divides when applying the rate, then rounds the monetary result to two decimal places using the chosen midpoint rule:

C#


public class Discount
{
    public Fraction Rate { get; private set; }

    public static Discount Create(int numerator, int denominator) =>
        new() { Rate = Fraction.Of(numerator, denominator) };

    public decimal Apply(decimal amount) =>
        Math.Round(amount * Rate.Numerator / Rate.Denominator, 2,
            MidpointRounding.AwayFromZero);
}

// Usage: amount taken off, not the remaining amount due
var discount = Discount.Create(1, 3);
var discountAmount = discount.Apply(10m); // Rounded to 3.33
Console.WriteLine(discountAmount);         // 3.33

Console.WriteLine(discount.Rate);      // 1/3  — the intent is preserved
            

Storing the fraction preserves the rate's intent; it does not make every decimal result exact. Choose the rounding scale and midpoint rule to match the business and currency requirements. The two decimal places and AwayFromZero rule here illustrate one policy for a two-decimal currency; other currencies and domains may require a different policy.

Step 3: Replace Formatted Address with an Address Value Object

Store each postal component as a typed field, not as a single concatenated string:

C#


public record Address
{
    public string Line1 { get; }
    public string? Line2 { get; }
    public string City { get; }
    public string PostCode { get; }
    public string CountryCode { get; }  // ISO 3166-1 alpha-2 format, e.g. "GB"

    private Address(
        string line1, string? line2,
        string city, string postCode, string countryCode)
    {
        if (string.IsNullOrWhiteSpace(line1))
            throw new ArgumentException("Address line 1 is required.", nameof(line1));
        if (string.IsNullOrWhiteSpace(city))
            throw new ArgumentException("City is required.", nameof(city));
        if (string.IsNullOrWhiteSpace(postCode))
            throw new ArgumentException("Post code is required.", nameof(postCode));
        var normalizedCountryCode = countryCode?.Trim();
        if (normalizedCountryCode is null ||
            normalizedCountryCode.Length != 2 ||
            normalizedCountryCode.Any(c =>
                !((c >= 'A' && c <= 'Z') || (c >= 'a' && c <= 'z'))))
            throw new ArgumentException(
                "Country code must contain two ASCII letters.", nameof(countryCode));

        Line1       = line1.Trim();
        Line2       = line2?.Trim();
        City        = city.Trim();
        PostCode    = postCode.Trim();
        CountryCode = normalizedCountryCode.ToUpperInvariant();
    }

    public static Address Of(
        string line1, string? line2,
        string city, string postCode, string countryCode) =>
        new(line1, line2, city, postCode, countryCode);

    // Derive the formatted mailing address on-demand — never store it
    public string Formatted =>
        string.Join(", ",
            new[] { Line1, Line2, City, PostCode, CountryCode }
            .Where(p => !string.IsNullOrWhiteSpace(p)));
}
            

Now the logistics service can group by city, the tax engine can read the country code, and the confirmation email can still render the formatted string—all from the same single stored value object:

C#


// Logistics: group shipments by city
var byCity = orders
    .GroupBy(o => o.ShippingAddress.City)
    .ToDictionary(g => g.Key, g => g.ToList());

// Tax: read country code directly
var vatRate = vatRules.GetRateFor(order.ShippingAddress.CountryCode);

// Email: render formatted string
var addressLine = order.ShippingAddress.Formatted;
// "14 Baker Street, London, NW1 6XE, GB"
            

Uppercasing the post code is a normalization policy for supported postal systems, not a universal address rule. Apply country-specific normalization only where the relevant postal rules allow it.

The factory validates the country-code format, not membership in the ISO 3166-1 alpha-2 list. Validate membership against an authoritative list when the domain requires a recognized code.

Step 4: Replace Audit Messages with Structured Audit Entries

Store before and after prices, the actor, and the timestamp as fields rather than a pre-rendered string. Here Money represents an amount and currency. The query below assumes both prices use the same currency. This example assumes Money exposes an amount and a string CurrencyCode:

C#


public record PriceChangeAudit
{
    public Guid ChangedBy { get; }
    public Money OldPrice { get; }
    public Money NewPrice { get; }
    public DateTimeOffset ChangedAt { get; }

    // Derive the human-readable message on-demand
    public string Summary =>
        $"Price changed from {OldPrice} to {NewPrice} " +
        $"by {ChangedBy} at {ChangedAt:O}";

    private PriceChangeAudit(
        Guid changedBy,
        Money oldPrice,
        Money newPrice,
        DateTimeOffset changedAt)
    {
        ChangedBy = changedBy;
        OldPrice = oldPrice;
        NewPrice = newPrice;
        ChangedAt = changedAt;
    }

    public static PriceChangeAudit Record(
        Guid changedBy, Money oldPrice, Money newPrice)
    {
        if (!string.Equals(
                oldPrice.CurrencyCode,
                newPrice.CurrencyCode,
                StringComparison.Ordinal))
            throw new InvalidOperationException(
                "A price change must use the same currency.");

        return new(
            changedBy, oldPrice, newPrice, DateTimeOffset.UtcNow);
    }
}
            

The query uses a half-open UTC interval: include the start instant and exclude the next quarter's start. If the business defines quarters in a local time zone, calculate those boundaries in that time zone before converting them to UTC. The GBP assumption must also hold when recording each price change; do not subtract raw amounts from different currencies.

With structured fields, the compliance query is direct:

C#


// Compliance: changes greater than £20 during Q1 2026.
// This query defines Q1 in UTC and assumes both prices use GBP.
var q1Start = new DateTimeOffset(2026, 1, 1, 0, 0, 0, TimeSpan.Zero);
var q2Start = new DateTimeOffset(2026, 4, 1, 0, 0, 0, TimeSpan.Zero);

var significantChanges = auditLog
    .Where(a => a.ChangedAt >= q1Start && a.ChangedAt < q2Start)
    .Where(a => a.OldPrice.CurrencyCode == "GBP")
    .Where(a => Math.Abs(a.NewPrice.Amount - a.OldPrice.Amount) > 20m)
    .OrderByDescending(a => a.ChangedAt)
    .ToList();

// And the human-friendly log still works
foreach (var entry in significantChanges)
    Console.WriteLine(entry.Summary);
            

Step 5: Replace the Single Loyalty Points Balance with Its Source Data

Store earned and redeemed totals separately, then calculate the balance from them. Splitting Points into PointsEarned and PointsRedeemed (both LoyaltyPoints Value Objects supporting arithmetic and comparison operators) and computing the balance on-demand makes the current totals explicit. These illustrative comparisons assume LoyaltyPoints defines the required operators and an implicit conversion from integers. Alternatively, represent 250 as a named LoyaltyPoints value.

C#


public class Customer : Entity
{
    public LoyaltyPoints PointsEarned   { get; private set; } = LoyaltyPoints.Zero;
    public LoyaltyPoints PointsRedeemed { get; private set; } = LoyaltyPoints.Zero;

    // Derive the balance — never store it
    public LoyaltyPoints Points => PointsEarned - PointsRedeemed;

    public void IncreaseEarnedPoints(LoyaltyPoints points)
    {
        PointsEarned += points;
    }

    public void ReduceEarnedPoints(LoyaltyPoints points)
    {
        if (points > Points)
            throw new InvalidOperationException(
                "Cannot remove points that have already been redeemed.");

        PointsEarned -= points;
    }

    public void RedeemPoints(LoyaltyPoints points)
    {
        if (Points < 250 || points > Points)
            throw new InvalidOperationException(
                "The customer cannot redeem this amount.");

        PointsRedeemed += points;
    }
}
            

Each method now expresses a distinct business operation. IncreaseEarnedPoints and ReduceEarnedPoints handle order adjustments without the redemption eligibility rule. This example rejects an adjustment that would make the balance negative; a system with a different policy should model that explicitly. RedeemPoints handles customer redemption with full validation. The separate totals make those operations and their rules explicit.

The model can also display earned and redeemed totals separately. The balance alone did not retain either total.

The guideline can be applied one step further. PointsEarned is itself derived—it is the sum of loyalty points from each order. Storing the orders instead makes PointsEarned computable rather than persisted:

C#


public class Customer : Entity
{
    public Order[] Orders               { get; private set; } = Array.Empty<Order>();
    public LoyaltyPoints PointsRedeemed { get; private set; } = LoyaltyPoints.Zero;

    // Both are derived — neither is stored
    public LoyaltyPoints PointsEarned =>
        Orders.Aggregate(
            LoyaltyPoints.Zero,
            (total, order) => total + order.LoyaltyPoints);
    public LoyaltyPoints Points        => PointsEarned - PointsRedeemed;

    public void RedeemPoints(LoyaltyPoints points)
    {
        if (Points < 250 || points > Points)
            throw new InvalidOperationException(
                "The customer cannot redeem this amount.");

        PointsRedeemed += points;
    }
}
            

Because LoyaltyPoints is a custom type, this aggregate calculation assumes it defines Zero and an addition operator. It also assumes the array contains all relevant orders before the balance is calculated and that LINQ is in scope. This is an in-memory sketch; persisted models can calculate the total with a database query instead of loading every order.

This version derives earned points from the associated orders, so changes to order points become the source of that total. Event Sourcing is a separate architectural choice that stores a sequence of domain events; it is not a required endpoint of this modeling approach. Choose the simplest model that preserves the facts and history your application needs.

Step 6: Apply the Richest Form Checklist Before Finalising a Value Object

Before marking a value object as complete, ask these questions:

markdown


Richest Form Checklist
======================

1. Can a stored property be derived from other stored properties?
   - YES → consider removing the derived property and computing it.
   - NO  → continue.

2. Is any stored property a concatenation or aggregation of smaller facts?
   - YES → split those facts into individual typed properties.
   - NO  → continue.

3. Is any stored property a decimal approximation of a fraction that cannot be expressed exactly in base 10?
   - YES → store numerator and denominator; derive the decimal on use.
   - NO  → continue.

4. Is any stored property a human-readable string that contains structured data?
   - YES → parse the structure into typed fields; derive the string on use.
   - NO  → continue.

5. Is any stored property a derived total of upstream source values?
   - YES → store the source values separately; derive the total on-demand.
   - NO  → continue.

6. Would a derived value need to be persisted for performance or snapshot consistency?
   - YES → persist it deliberately and define how it stays consistent.
   - NO  → derive it from its source facts.
            

Here is a summary of the before-and-after transformations from all five examples:

markdown


Scenario            | Reduced Form (Avoid)        | Richest Form (Prefer)
--------------------|-----------------------------|----------------------------------------------
Person Name         | "Abdul Rahman"              | First: "Abdul" + Last: "Rahman"
Discount Rate       | 0.3333333...                | Numerator: 1, Denominator: 3
Shipping Address    | "14 Baker St, London"       | Line1, City, PostCode, CountryCode
Audit Change        | "Price changed to £79"      | OldPrice: £49, NewPrice: £79, ChangedAt
Loyalty Points      | int Points (remainder)      | PointsEarned + PointsRedeemed (computed: Points)
            

Preserve the source facts and distinctions that the domain needs. Derive presentation values when the source facts and formatting rules are available, and persist calculated values deliberately when the application requires them.

Summary

Storing data in its richest form means preserving the domain-relevant facts needed for decisions, queries, and future changes. It does not mean modeling every possible detail or avoiding all derived values.

Key takeaways:

  • Derive values when practical: Format and calculate from source facts when the rules are available. Persist derived values deliberately when performance or snapshot consistency requires it.
  • Discarded distinctions cannot be inferred reliably: Do not assume a display name contains recoverable first-name and last-name boundaries.
  • Preserve rates when precision matters: Store a numerator and denominator when the rate is rational, then apply the required rounding policy to monetary results.
  • Strings do not preserve structure by themselves: Model known, domain-relevant components as typed fields instead of trying to infer them from display text.
  • Value Objects represent domain rules: Use a record with a controlled factory when it helps keep valid, domain-specific values together.

Use the Richest Form Checklist to review whether your model retains the facts the application needs and whether derived values have an explicit consistency policy.