Guides

Fan-out

Child counts and customizers multiply per parent and come back as one flat array.

Per parent, in parent order

A class-capacity report may need two classes with three students each. Add the students while the anchor holds both classes. Counts and customizers apply to each parent, and the result is one flat array in parent order.

FanOutTests.cs
await TestBiome
    .Start(out _)
    .AddDistrict(out _)
    .AddSchool(out _)
    .AddClasses(out var classes, 2)
    // Three students per class, in class order. The first three belong to classes[0].
    .AddStudents(out var students, 3)
    .BuildAsync();

Customizers per parent

Each customizer creates one entity per parent. Here each class gets a student named Maya in the first seat and a student with a default name in the second seat.

ClassRosterTests.cs
await TestBiome
    .Start(out _)
    .AddDistrict(out _)
    .AddSchool(out _)
    .AddClasses(out _, 2)
    .AddStudents(
        out var students,
        // Each class gets Maya in seat 1 and a default name in seat 2.
        s => s.FullName = "Maya Chen",
        _ => { }
    )
    .BuildAsync();

A staffing report needs a small class and a large class at each school. The two customizers express the two capacities, while the blueprint supplies the links and timestamps.

await TestBiome
    .Start(_db, out _)
    .AddDistrict(out _)
    .AddSchools(out var schools, 2)
    // Each school gets a 12-seat class and a 36-seat class, in that order.
    .AddClasses(out var classes, c => c.Capacity = 12, c => c.Capacity = 36)
    .BuildAsync();

Parent-aware customizers

A child customizer in the two-parameter form receives a ChildContext:

MemberMeaning
ctx.ParentThis child's parent, typed.
ctx.ParentIndexThe parent's position in the anchor array.
ctx.IndexThe child's position under that parent.
Parent-aware
await TestBiome
    .Start(out _)
    .AddDistrict(out _)
    .AddSchools(out _, s => s.Code = "NH", s => s.Code = "SH")
    .Add(
        Blueprints.Class,
        out var classes,
        // Use the current parent’s code to distinguish the two class names.
        (schoolClass, ctx) => schoolClass.Name = $"{ctx.Parent.Code} Algebra I"
    )
    .BuildAsync();
An index describes position in this Add, so it is useful for a display label. It restarts on the next call and cannot guarantee uniqueness. Use sequences for numbering and ordering, or ctx.NewId for IDs.

A base-context trait works for children too

A trait written against BiomeContext<TSeed> is assignable to the child's ChildContext form. For example, use a shared trait to backdate a student's enrollment and a child-aware customizer to record where the second student was added.

ClassRosterTests.cs
var positions = new List<(int Parent, int Child)>();

// This trait only needs the clock, so it can accept the base context.
Action<Student, BiomeContext<SchoolSeed>> returning = (student, ctx) =>
    student.EnrolledAtUtc = ctx.Ago(TimeSpan.FromDays(30));

await TestBiome
    .Start(out _)
    .AddDistrict(out _)
    .AddSchool(out _)
    .AddClasses(out _, 2)
    .Add(
        Blueprints.Student,
        out var students,
        // Use the same trait here alongside a customizer that needs the child context.
        returning,
        (_, ctx) =>
        {
            positions.Add((ctx.ParentIndex, ctx.Index)); // Adds (0, 1) and (1, 1).
        }
    )
    .BuildAsync();

Singular child adds need one parent

A singular child Add needs one parent so its out value can identify one child. After AddClasses(out var classes, 2), use the plural Add for both classes or select one with .Under(classes[0]). A singular child Add with zero or multiple parents throws.