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
<PackageReference Include="MsSql.ClassGenerator.Core" Version="1.0.0" />
<PackageVersion Include="MsSql.ClassGenerator.Core" Version="1.0.0" />
<PackageReference Include="MsSql.ClassGenerator.Core" />
paket add MsSql.ClassGenerator.Core --version 1.0.0
#r "nuget: MsSql.ClassGenerator.Core, 1.0.0"
#:package MsSql.ClassGenerator.Core@1.0.0
#addin nuget:?package=MsSql.ClassGenerator.Core&version=1.0.0
#tool nuget:?package=MsSql.ClassGenerator.Core&version=1.0.0
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:
TableManager: Provides the function to load table information.ClassManager: Provides the functions to generate C# classes from the table information (point 1).
ToDos
- Testing: Testing of all different combinations of the options.
- 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
nullfor 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 | Versions 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. |
-
net9.0
- Dapper (>= 2.1.66)
- Microsoft.Data.SqlClient (>= 6.0.1)
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 |