Reference

API Integration

Minimal wiring to call generated procedures from ASP.NET Core (or any DI host), with room to add policies and streaming later.

Register the services

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddXtraqDbContext(options =>
{
    options.ConnectionString = builder.Configuration.GetConnectionString("DefaultConnection")
        ?? throw new InvalidOperationException("Missing 'DefaultConnection'.");
});

var app = builder.Build();

Session settings (optional)

SessionSettings applies SQL Server SET flags right after opening a connection. Standard default: QUOTED_IDENTIFIER, ANSI_NULLS, ANSI_PADDING, ANSI_WARNINGS, CONCAT_NULL_YIELDS_NULL, ARITHABORT, NOCOUNT ON; NUMERIC_ROUNDABORT OFF. Override if needed:

builder.Services.AddXtraqDbContext(options =>
{
    options.ConnectionString = "...";
    options.SessionSettings.Clear()
        .WithQuotedIdentifierOn()
        .WithAnsiNullsOn()
        .WithAnsiPaddingOn()
        .WithAnsiWarningsOn()
        .WithConcatNullYieldsNull()
        .WithArithAbortOn()
        .WithNoCountOn()
        .WithNumericRoundAbortOff();
});

Call a procedure (minimal handler)

app.MapPost("/orders", async (
    OrderCreateInput input,
    IXtraqDbContext db,
    CancellationToken ct) =>
{
    var result = await db.ConfigureProcedure(input)
        .ExecuteAsync(ctx => ctx.OrderCreateAsync, ct);

    return Results.Ok(result);
});

Optional extras (add as needed)

  • .WithTransaction() to wrap execution in the generated transaction scope.
  • .WithPolicy(...) for retries/telemetry wrappers.
  • ConfigureProcedure<TRequest, TInput>(request, mapper) when you accept request DTOs and need the generated mapper.
  • Streaming helpers (ConfigureProcedureStream) expose the same pattern for NDJSON or server-sent streams.

More detail?