Skip to content

Search EricksonLopez.* Ecosystem

Type a library name, NuGet package ID, .NET type, or architectural concept to search across the portal.

Guides & Recipes — SqlBuilder

Compiled and analyzer-verified (SqlBuilder.Analyzers + SqlBuilder.SourceGenerators) recipes for .NET 10.

using EricksonLopez.Pagination.Abstractions;
using EricksonLopez.SqlBuilder;
using EricksonLopez.SqlBuilder.Abstractions;
using EricksonLopez.SqlBuilder.Pagination;
using EricksonLopez.SqlBuilder.PostgreSql;
namespace Example.SqlBuilderQuickStart;
public static class CursorQueryRecipe
{
public static SqlResult BuildCursorSelect(CursorPaginationParameters parameters)
{
var compiler = new PostgreSqlCompiler();
SelectQuery<OrderRecord> paged = Sql.From<OrderRecord>()
.Where(o => o.CustomerId == 42L)
.ApplyCursor(parameters, o => o.Id, ascending: false);
return compiler.Compile(paged);
}
}
using System;
using System.Collections.Generic;
using System.Data;
using System.Threading;
using System.Threading.Tasks;
using EricksonLopez.SqlBuilder;
using EricksonLopez.SqlBuilder.Abstractions;
using EricksonLopez.SqlBuilder.Aot;
using EricksonLopez.SqlBuilder.PostgreSql;
namespace Example.SqlBuilderQuickStart;
public static class AotQueryRecipe
{
public static Task<IReadOnlyList<OrderRecord>> QueryPreCompiledAotAsync(
IDbConnection connection,
long customerId,
CancellationToken ct)
{
FormattableString sql = $"SELECT id, customer_id, status, total FROM orders WHERE customer_id = {customerId}";
RawQuery raw = Sql.Raw(sql);
SqlResult precompiled = new PostgreSqlCompiler().Compile(raw);
return connection.AotQueryAsync(precompiled, OrderRecord.GetReaderParser(), cancellationToken: ct);
}
}