Core Concepts — Immutable AST, Dialect Compilers & AOT Execution
EricksonLopez.SqlBuilder separates immutable query construction (Sql.From<T>(), Sql.Insert, Sql.Update<T>(), Sql.Delete<T>(), Sql.Raw(FormattableString)) from dialect compilation and ADO.NET/Dapper execution.
Immutable Record Branching & Parameter Safety
Section titled “Immutable Record Branching & Parameter Safety”- Query builders produce immutable AST nodes (
FromNode,WhereNode,LimitNode, etc.). Branching a shared base query (var baseQ = Sql.From<OrderRecord>().Where(o => o.CustomerId == 42L);) never mutatesbaseQ. Sql.Raw(FormattableString)captures interpolated arguments as SQL parameters automatically (ESQL011flags rawstringoverloads).DeleteQuery<T>guards against missing.Where(...)clauses at runtime unless explicitly structured.
Native AOT Boundary: Pre-Compiled SqlResult vs ISqlQuery
Section titled “Native AOT Boundary: Pre-Compiled SqlResult vs ISqlQuery”ISqlCompiler.Compile(ISqlQuery)andAotQueryAsync(ISqlQuery, ISqlCompiler, ...): Carry[RequiresDynamicCode]and[RequiresUnreferencedCode]because compiling LINQ lambda predicates inspects expression trees.- Zero-warning Native AOT execution: Pre-compile static
RawQueryor query definitions intoSqlResultand pass thatSqlResulttoconnection.AotQueryAsync(precompiled, OrderRecord.GetReaderParser(), cancellationToken: ct)(EricksonLopez.SqlBuilder.Aot) orAotDapperExtensions.AotQueryAsync(connection, precompiled, mapper)(EricksonLopez.SqlBuilder.Dapper.Aot). - Source Generator (
SqlBuilder.SourceGenerators): GeneratesIStaticEntityMetadata<T>andGetReaderParser()on[SqlEntity("table")] public partial class ...types with zero runtime reflection.