Mapping

Map rows to .NET types

Fusion adapts to an existing schema. Mapping remains explicit, and materialization accepts either one complete public constructor or a public parameterless constructor followed by public setters.

Records and keys

DbKey identifies the key used to deduplicate joined rows and track changes. C# records are materialized through their complete constructor.

Models.cs
public sealed record Person(
    [property: DbKey]
    long ID,
    string LastName,
    string FirstMidName,
    DateTime EnrollmentDate,
    string Discriminator);

public sealed record Course(
    [property: DbKey]
    long CourseID,
    string Title,
    int Credits,
    long DepartmentID);

public sealed record Department(
    [property: DbKey]
    long DepartmentID,
    string Name,
    decimal Budget,
    long InstructorID);

public sealed record OfficeAssignment(
    [property: DbKey]
    long InstructorID,
    string Location);

public sealed record CourseAssignment(
    [property: DbKey]
    long InstructorID,
    [property: DbKey]
    long CourseID);

public sealed record DepartmentDto(
    long Id,
    string Name,
    decimal Budget,
    long InstructorId,
    List<CourseDto> Courses);

public sealed record CourseDto(
    long Id,
    string Title,
    int Credits);

Mapping attributes

DbTable

Maps a type to a table and, when needed, its schema.

DbColumn

Maps a property to a column with a different name.

DbKey

Declares one or more key properties.

DbIgnore

Excludes a property from mapping.

DbReadOnly

Reads a property without including it in generated writes.