SqlCodeGen 1.0.2

There is a newer version of this package available.
See the version list below for details.
dotnet add package SqlCodeGen --version 1.0.2
                    
NuGet\Install-Package SqlCodeGen -Version 1.0.2
                    
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="SqlCodeGen" Version="1.0.2">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="SqlCodeGen" Version="1.0.2" />
                    
Directory.Packages.props
<PackageReference Include="SqlCodeGen">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
                    
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 SqlCodeGen --version 1.0.2
                    
#r "nuget: SqlCodeGen, 1.0.2"
                    
#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 SqlCodeGen@1.0.2
                    
#: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=SqlCodeGen&version=1.0.2
                    
Install as a Cake Addin
#tool nuget:?package=SqlCodeGen&version=1.0.2
                    
Install as a Cake Tool

SqlCodeGen

A Roslyn Source Generator that generates C# EF Core binding classes and TypeScript enums from SQL schema files.

Features

  • No database connection required - Reads SQL files directly from your database project
  • C# generation: Entity binding classes, PrimaryKey wrappers, navigation properties
  • TypeScript generation: Enum definitions, lookup arrays, dropdown options
  • Incremental generation - Only regenerates when SQL files change
  • Git history preservation - Writes to disk with same filenames for clean diffs

Installation

<PackageReference Include="SqlCodeGen" Version="1.0.0"
                  OutputItemType="Analyzer"
                  ReferenceOutputAssembly="false" />

Configuration

Add to your EF Models project .csproj:

<PropertyGroup>
  
  <SqlCodeGen_Namespace>MyProject.EFModels.Entities</SqlCodeGen_Namespace>

  
  <SqlCodeGen_TypeScriptOutputDir>..\MyProject.Web\src\app\shared\generated\enum</SqlCodeGen_TypeScriptOutputDir>

  
  <SqlCodeGen_OutputDir>Entities\Generated\ExtensionMethods</SqlCodeGen_OutputDir>

  
  <SqlCodeGen_ExcludeTables>DatabaseMigration,__RefactorLog</SqlCodeGen_ExcludeTables>
</PropertyGroup>


<Import Project="..\SqlCodeGen\build\SqlCodeGen.props" />


<ItemGroup>
  <AdditionalFiles Include="..\MyProject.Database\dbo\Tables\*.sql" />
  <AdditionalFiles Include="..\MyProject.Database\Scripts\LookupTables\*.sql" />

  
  <SqlCodeGenTableSql Include="..\MyProject.Database\dbo\Tables\" />
  <SqlCodeGenLookupTableSql Include="..\MyProject.Database\Scripts\LookupTables\" />
</ItemGroup>


<ItemGroup Condition="'$(SqlCodeGen_OutputDir)' != ''">
  <Compile Remove="$(SqlCodeGen_OutputDir)\*.Binding.cs" />
  <Compile Remove="$(SqlCodeGen_OutputDir)\*PrimaryKey.cs" />
</ItemGroup>

What Gets Generated

For Lookup Tables (tables with MERGE files)

C# Binding Class ({TableName}.Binding.cs):

  • Static readonly instances for each enum value
  • All list and AllLookupDictionary for lookups
  • Strongly-typed enum
  • ToType() and ToEnum conversion methods
  • Navigation properties to other lookup tables

TypeScript Enum ({table-name}-enum.ts):

  • Enum definition
  • LookupTableEntry[] array
  • SelectDropdownOption[] for dropdowns

For Regular Tables

C# Binding Class ({TableName}.Binding.cs):

  • FieldLengths static class with max lengths for string columns
  • Navigation properties to lookup tables

For All Tables

C# PrimaryKey Wrapper ({TableName}PrimaryKey.cs):

  • Strongly-typed primary key wrapper class

SQL File Requirements

CREATE TABLE files (dbo/Tables/*.sql)

CREATE TABLE [dbo].[ProjectStage](
    [ProjectStageID] [int] NOT NULL,
    [ProjectStageName] [varchar](100) NOT NULL,
    [ProjectStageDisplayName] [varchar](100) NOT NULL,
    [SortOrder] [int] NOT NULL,
    CONSTRAINT [PK_ProjectStage] PRIMARY KEY CLUSTERED ([ProjectStageID])
)

MERGE files for lookup tables (Scripts/LookupTables/*.sql)

MERGE INTO [dbo].[ProjectStage] AS Target
USING (VALUES
    (1, 'Proposal', 'Proposal', 10),
    (2, 'PlanningDesign', 'Planning/Design', 20),
    (3, 'Implementation', 'Implementation', 30)
) AS Source (ProjectStageID, ProjectStageName, ProjectStageDisplayName, SortOrder)
ON Target.ProjectStageID = Source.ProjectStageID
WHEN MATCHED THEN UPDATE SET ...
WHEN NOT MATCHED THEN INSERT ...;

Development vs Production

This is a development-only dependency. The generated files are committed to git, so production builds just compile the checked-in files:


<ItemGroup Condition="'$(Configuration)' == 'Debug'">
  <PackageReference Include="SqlCodeGen" Version="1.0.0" ... />
</ItemGroup>

License

MIT

There are no supported framework assets in this package.

Learn more about Target Frameworks and .NET Standard.

  • .NETStandard 2.0

    • 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
1.0.8 86 2/4/2026
1.0.7 76 2/4/2026
1.0.6 68 2/3/2026
1.0.5 65 2/3/2026
1.0.4 72 2/3/2026
1.0.3 68 2/3/2026
1.0.2 71 2/3/2026
1.0.1 67 2/3/2026
1.0.0 72 2/3/2026