Mvp24Hours.Entity.Core 3.7.151

dotnet add package Mvp24Hours.Entity.Core --version 3.7.151                
NuGet\Install-Package Mvp24Hours.Entity.Core -Version 3.7.151                
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="Mvp24Hours.Entity.Core" Version="3.7.151" />                
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Mvp24Hours.Entity.Core --version 3.7.151                
#r "nuget: Mvp24Hours.Entity.Core, 3.7.151"                
#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.
// Install Mvp24Hours.Entity.Core as a Cake Addin
#addin nuget:?package=Mvp24Hours.Entity.Core&version=3.7.151

// Install Mvp24Hours.Entity.Core as a Cake Tool
#tool nuget:?package=Mvp24Hours.Entity.Core&version=3.7.151                

mvp24hours-entity-t4

How to use the Mvp24Hours.Entity.SqlServer and Mono.TextTemplating library to generate templates with T4.

Tools

Run the command below to install the T4 template engine:

dotnet tool install -g dotnet-t4

How to configure?

Add the configuration below to the .csproj file

<ItemGroup>
	<PackageReference Include="Mono.TextTemplating" Version="2.0.5" />
	<PackageReference Include="Mvp24Hours.Entity.SqlServer" Version="1.0.0" />
	<TextTemplate Include="**\*.tt" />
	<Generated Include="**\*.Generated.cs" />
</ItemGroup>

<Target Name="TextTemplateTransform" BeforeTargets="BeforeBuild">
	<Exec WorkingDirectory="$(ProjectDir)" Command="t4 %(TextTemplate.Identity) -c $(RootNameSpace).%(TextTemplate.Filename) -o %(TextTemplate.Filename).Generated.cs" />
</Target>

<Target Name="TextTemplateClean" AfterTargets="Clean">
	<Delete Files="@(Generated)" />
</Target>  

Create a file for the ITextTemplate interface:

public interface ITextTemplate
{
    string TransformText() => throw new NotImplementedException();
}	

Create the file that will represent the entity model or models loaded for use in ".tt", for example (ModelTemplate.cs):

public partial class ModelTemplate : ITextTemplate
{
    public readonly ResultSettings Models;
    public readonly EntitySettings Entity;

    public ModelTemplate(ResultSettings models, EntitySettings entity)
        => (Models, Entity) = (models, entity);
}

Create a file with the extension ".tt" with the same name as the previous class, for example (ModelTemplate.tt):

<#@ template language="C#" #>
<#@ assembly name="System.Core" #>
<#@ import namespace="System.Linq" #>
<#@ import namespace="System.Collections.Generic" #>

<#=Entity.Name#>

The same properties of your "ModelTemplate" class can be used in your "ModelTemplate.tt" template.

Ready! Now just run your "Program.cs" with combining the template with the models loaded from the database:

var mvpSettings = new Mvp24Settings()
{
    Database = new DatabaseSettings()
    {
        DataSource = "",
        Catalog = "",
        TrustedConnection = true
    },
    IdKeyName = true, // Use if the columns that represent your table's primary key have the name "ID"
    TableFilter = "", // Use to filter the tables you want to read
};

var dbEntity = new DbEntitySqlServer(mvpSettings);
var settings = dbEntity.GetSettings();

if (settings != null)
{
    System.Console.WriteLine("Writing processed results in the \"Models\" folder..");

    string pathDir = ""; // What is the output directory of the processed files?

    foreach (var entity in settings.Entities)
    {
        System.Console.WriteLine($"Writing {entity.ClassName}.cs");
        ITextTemplate template = new ModelTemplate(settings, entity);
        File.WriteAllText($"{pathDir}{entity.ClassName}.cs", template.TransformText());
    }
}

When the project is compiled, a "Generated" file (ModelTemplate.Generated.cs) will be generated that corresponds to the processed template.

How to Configure Using a JSON File?

If you want to use a configuration file, create a ".json" file with the following structure:

{
  "database": {
    "datasource": "",
    "catalog": "",
    "trustedconnection": "true",
    "username": "",
    "password": ""
  },
  "generate": true,
  "schemafilter": "",
  "tablefilter": "",
  "idkeyname": false
}

Just inform the name of the file that is in the same directory when creating the "DbEntitySqlServer" object, like this:

var dbEntity = new DbEntitySqlServer("mvp24hours-entity-settings.json");
var settings = dbEntity.GetSettings();	
Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed. 
.NET Core netcoreapp3.1 is compatible. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (3)

Showing the top 3 NuGet packages that depend on Mvp24Hours.Entity.Core:

Package Downloads
Mvp24Hours.Entity.SqlServer

Package Description

Mvp24Hours.Entity.PostgreSql

Package Description

Mvp24Hours.Entity.MySql

Package Description

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
3.7.151 99 7/15/2024
2.2.21 806 2/2/2022
1.5.311 457 5/31/2021
1.0.2 413 3/12/2021
1.0.1 379 3/5/2021
1.0.0 475 3/4/2021