Reading

Execute explicit SQL

Fusion does not generate business queries. You write the SQL and choose the result shape: a scalar value, typed rows, or a custom projection.

Typed rows

GetRowsAsync<T> materializes each row into the requested type. Column names and types must explicitly match the model.

ListCourses.cs
await using var fusionConnection = await context.OpenFusionConnectionAsync();

var courses = await fusionConnection.GetRowsAsync<Course>(
    """
    SELECT CourseID, Title, Credits, DepartmentID
    FROM Course
    ORDER BY CourseID;
    """
);

return courses;

Scalar value and named parameters

GetValueAsync<T> reads one value. Parameters retains the CLR type of each value so that the provider can create the appropriate ADO.NET parameters.

ScalarAndParameters.cs
await using var fusionConnection = await context.OpenFusionConnectionAsync();

var parameters = new Parameters
{
    { "minimumCredits", 4 }
};

var courseCount = await fusionConnection.GetValueAsync<long>(
    """
    SELECT COUNT(*)
    FROM Course
    WHERE Credits >= @minimumCredits;
    """,
    parameters,
    context.CancellationToken);

return courseCount;

Custom projection

GetProjectionsAsync provides access to FusionDataRecord. Successive calls to ReadValue<T> follow the column order in the SELECT list.

ProjectionCourses.cs
await using var fusionConnection = await context.OpenFusionConnectionAsync();

var courses = await fusionConnection.GetProjectionsAsync(
    """
    SELECT Title, Credits
    FROM Course
    WHERE DepartmentID = @departmentId
    ORDER BY Title;
    """,
    row => new
    {
        Title = row.ReadValue<string>(),
        Credits = row.ReadValue<long>()
    },
    new Parameters { { "departmentId", 1 } },
    context.CancellationToken);

return courses;