RSCG_Sql 2026.11.1.1516
dotnet add package RSCG_Sql --version 2026.11.1.1516
NuGet\Install-Package RSCG_Sql -Version 2026.11.1.1516
<PackageReference Include="RSCG_Sql" Version="2026.11.1.1516" />
<PackageVersion Include="RSCG_Sql" Version="2026.11.1.1516" />
<PackageReference Include="RSCG_Sql" />
paket add RSCG_Sql --version 2026.11.1.1516
#r "nuget: RSCG_Sql, 2026.11.1.1516"
#:package RSCG_Sql@2026.11.1.1516
#addin nuget:?package=RSCG_Sql&version=2026.11.1.1516
#tool nuget:?package=RSCG_Sql&version=2026.11.1.1516
RSCG_Sql
RSCG_Sql.Generator is a netstandard2.0 Roslyn incremental source generator that reads .sql files registered as AdditionalFiles. It parses each GO-separated batch with Microsoft ScriptDom and generates asynchronous methods in a SqlCommands class in the consuming project's RootNamespace. It emits one source file per SQL AdditionalFile, named using its relative folders and file name joined by underscores (for example, Sql\Commands.sql becomes Sql_Commands.g.cs). The tests and sample target .NET 10.
Use
Register the generator project as an analyzer and add your SQL file as an additional file:
<ProjectReference Include="..\RSCG_Sql.Generator\RSCG_Sql.Generator.csproj"
OutputItemType="Analyzer"
ReferenceOutputAssembly="false" />
<Analyzer Include="..\RSCG_Sql.Generator\bin\$(Configuration)\netstandard2.0\Microsoft.SqlServer.TransactSql.ScriptDom.dll" />
<AdditionalFiles Include="Sql\Commands.sql" />
<CompilerVisibleProperty Include="MSBuildProjectDirectory" />
Annotate each batch with a method name. @Returns names the row type for a SELECT; @IdType is required for inserts that return an identity:
-- @Name FindPerson
-- @Returns Person
SELECT id, name FROM people WHERE id = @id;
GO
-- @Name InsertPerson
-- @IdType long
INSERT INTO people(name) VALUES (@name);
SELECT last_insert_rowid();
Generated methods accept an already-open DbConnection, one argument for each SQL variable reference, and an optional CancellationToken. They do not open/close connections or create transactions. Annotated result rows are materialized with a public parameterless constructor and public writable properties matched to result column names without case sensitivity. UPDATE and DELETE batches return the sum of affected rows; non-query DDL batches return Task.
Supported syntax and mappings
- Batches are separated by a standalone
GOline; SQL comments use--. - Supported operation forms are
SELECTwith@Returns,INSERTwith@IdTypeand a recognized identity expression,UPDATE/DELETE, and non-query statements such as DDL. Each batch produces one method. - Identity expressions recognized by the generator are SQL Server
@@IDENTITY,SCOPE_IDENTITY(),IDENT_CURRENT(...), andOUTPUT INSERTED.ID; SQLitelast_insert_rowid(); and PostgreSQLcurrval(...). Only SQLite is covered by integration tests. - SQL declaration types map naturally: integer, bigint, smallint, tinyint, bit, uniqueidentifier, decimal/numeric/money, float/real, date/datetime, time, binary, and character/text types map to their corresponding C# primitives,
Guid,DateTime,TimeSpan,byte[], andstring. Types the generator cannot infer useobject?. - SQL dialect extensions must be accepted by the SQL Server ScriptDom parser. Malformed batches, missing/invalid annotations, unsupported identity forms, ambiguous result sets, and duplicate method names produce compiler errors rather than generated fallback behavior.
Build and tests
dotnet build RSCG_Sql.slnx
dotnet test RSCG_Sql.Tests\RSCG_Sql.Tests.csproj
The test project executes generated methods against an in-memory SQLite database. RSCG_Sql.Sample is a runnable console consumer demonstrating the same integration.
Learn more about Target Frameworks and .NET Standard.
This package has no dependencies.
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 2026.11.1.1516 | 110 | 11/1/2026 |