MsSql.ClassGenerator.Core 1.0.0

dotnet add package MsSql.ClassGenerator.Core --version 1.0.0
                    
NuGet\Install-Package MsSql.ClassGenerator.Core -Version 1.0.0
                    
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="MsSql.ClassGenerator.Core" Version="1.0.0" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="MsSql.ClassGenerator.Core" Version="1.0.0" />
                    
Directory.Packages.props
<PackageReference Include="MsSql.ClassGenerator.Core" />
                    
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 MsSql.ClassGenerator.Core --version 1.0.0
                    
#r "nuget: MsSql.ClassGenerator.Core, 1.0.0"
                    
#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 MsSql.ClassGenerator.Core@1.0.0
                    
#: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=MsSql.ClassGenerator.Core&version=1.0.0
                    
Install as a Cake Addin
#tool nuget:?package=MsSql.ClassGenerator.Core&version=1.0.0
                    
Install as a Cake Tool

MsSql.ClassGenerator.Core

This class library offers the possibility to generate a C# class from an SQL table.

The code originally comes from the MsSqlToolBelt project, which was optimized for the MsSql.ClassGenerator project. Since the functions are spread across two different projects, it was time to extract the code and provide it as a standalone library.

The class library is quite simple and contains the following two non-static classes:

  1. TableManager: Provides the function to load table information.
  2. ClassManager: Provides the functions to generate C# classes from the table information (point 1).

ToDos

  1. Testing: Testing of all different combinations of the options.
  2. Release: Release of the first version.

Example

var classManager = new ClassManager();
        classManager.ProgressEvent += (_, message) => Console.WriteLine(message);
        var generatorResult = await classManager.GenerateClassesAsync(tables, new ClassGeneratorOptions
        {
            Namespace = "TestNamespace",
            SealedClass = false,
            Modifier = ClassModifier.Internal,
            DbModel = true,
            AddColumnAttribute = false,
            WithBackingField = false,
            AddSetProperty = false,
            AddSummary = true,
            AddTableNameToClassSummary = true,
            AdditionalInformationFilepath = Path.Combine(AppContext.BaseDirectory, "TableInformation.json")
        });

For a detailed example, see the demo project.

Property Description
Namespace The desired namespace which should be used. If the value is empty (e. g. string.Empty or "") only the bare class is created (without namespace and usings).
SealedClass If true, the sealed modifier is added.
Modifier The desired modifier. Default = private.
DbModel If true, a class is created which can be used with EF Core.
AddColumnAttribute If true, the [Column("Name")] attribute is added to each property even if it's not needed.
WithBackingField If true, a backing field is created.
AddSetProperty If true, the SetProperty method and the using of the CommunityToolkit.Mvvm is added.
AddSummary If true, a summary is added to the class / property.
AddTableNameToClassSummary If true, the name of the table is added to the class summary. Is added as remarks.
AdditionalInformatilFilepath The path of the file, which contains the additional information.

Additional information

It is possible to provide additional information for a class/property. This is done via a JSON file with the following structure:

[
  {
    "Table": "Book",
    "Column": null,
    "Summary": "Represents a single book.",
    "Remarks": "Test remarks entry."
  }
]
Key Data type Description
Table string The name of the desired table.
Column string? (nullable) The name of the column.
Summry string The desired text for the summary.
Remarks string The desired text for the remarks.

Note: The information for a class is indicated by the value null for the Column. For an example see here Example

Templates / Type Conversion file

After you build your project, a folder named "Files" will be created. Inside you'll find the following files:

File Description
ClassDefault.cgt The template for a default class without a namespace (the bare class without a namespace and without the usings).
ClassDefaultWithNs.cgt The template for a class with a namespace (includes the usings).
PropertyBackingField.cgt The template for a property with a backing field.
PropertyBackingFieldSetProperty.cgt The template for a property with a backing field and the usage of the SetProperty method (for more information see Example > AddSetProperty).
PropertyDefault.cgt The template for property (without backing field).
TypeConverstion.json The file containing the information for converting an MS SQL data type to the corresponding C# data type.

Note: The content of the files can/may be changed, but the file name must not be changed, otherwise they can no longer be found and an error will occur.

Product Compatible and additional computed target framework versions.
.NET net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

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.0 329 4/14/2025