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
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="RSCG_Sql" Version="2026.11.1.1516" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="RSCG_Sql" Version="2026.11.1.1516" />
                    
Directory.Packages.props
<PackageReference Include="RSCG_Sql" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add RSCG_Sql --version 2026.11.1.1516
                    
#r "nuget: RSCG_Sql, 2026.11.1.1516"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package RSCG_Sql@2026.11.1.1516
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=RSCG_Sql&version=2026.11.1.1516
                    
Install as a Cake Addin
#tool nuget:?package=RSCG_Sql&version=2026.11.1.1516
                    
Install as a Cake Tool

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 GO line; SQL comments use --.
  • Supported operation forms are SELECT with @Returns, INSERT with @IdType and 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(...), and OUTPUT INSERTED.ID; SQLite last_insert_rowid(); and PostgreSQL currval(...). 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[], and string. Types the generator cannot infer use object?.
  • 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.

There are no supported framework assets in this package.

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