Guides

Transients

Build an entity and return it without saving it.

Inputs the code under test should create

A test for student enrollment needs a saved class and a student to add to it. Saving the student during setup would do the work that the test is supposed to exercise. Mark the student transient to get the blueprint's valid defaults while keeping the row out of Biome's save list.

await TestBiome
    .Start(_db, out _)
    .AddDistrict(out _)
    .AddSchool(out _)
    .AddClass(out _)
    // Leave the student unsaved so EnrollAsync can insert it.
    .AddStudent(out var student, s => s.FullName = "Mina Ortiz")
    .Transient()
    .BuildAsync();

Two ways to mark one

FormScopeUse
.Transient() on the builderThe most recent Add stepOne test needs an unsaved input.
bp.AsTransient() on a blueprintEvery use of that blueprintThe entity is always an input.

An EnrollmentRequest is a request DTO with a ClassId and a nullable FullName. Every use is transient, so the blueprint can carry that choice.

Blueprints.cs
public static readonly ChildBlueprint<
    SchoolSeed,
    SchoolClass,
    EnrollmentRequest
> EnrollmentRequest = Blueprint
    .ChildOf<SchoolSeed, SchoolClass, EnrollmentRequest>(
        (schoolClass, _) => new() { ClassId = schoolClass.Id }
    )
    .Derive(r => r.FullName, (_, _) => "Mina Ortiz")
    // Keep every request out of the save list because the service consumes it as input.
    .AsTransient();
Builders share a session, and .Transient() marks that session's most recent Add step. Place it immediately after the intended step so its scope is clear, even if you keep an earlier builder in a variable.

Transient entities are still inspectable. biome.All<T>() includes them, and out variables hold them. A transient aggregate excludes all of its parts from the save.

EnrollmentTests.cs
var biome = TestBiome.Start(_db, out _);
await biome
    .AddDistrict(out _)
    .AddSchool(out _)
    .AddClasses(out var classes, 2)
    .AddStudents(out _, 3)
    .Under(classes)
    .AddEnrollmentRequests(out _, 1)
    .BuildAsync();

// The requests are still in the session after the save.
await Assert.That(biome.All<EnrollmentRequest>().Count).IsEqualTo(2);
Excluding a row from Biome's save list does not stop EF Core from discovering it through a saved row's navigation. If the input must stay unsaved, remove that reference or make the referencing row transient too.