Code Generators

You can inspire from the Git Hub Sample Project where to place the code generator scripts, it will also make the modification of your project folders' relative paths clear to you. You can also download all text templates of the code generator scripts for specific databases at Downloads

Quick Overview of Code Generators

EntitiesFromEFCore.tt

  1. Generate EF Core entities from your database using scaffold command in your EDI command line or ordinary command line accessing dotnet.exe. 

       dotnet tool install --global dotnet-ef --version 6.0
       dotnet ef dbcontext scaffold "Server=localhost;Database=d3orm_sample;Uid=d3orm;Pwd=***;" Pomelo.EntityFrameworkCore.MySql --startup-project ./KLO128.D3ORM.Sample.Infra.EFCore.MySQL.Gen --project ./KLO128.D3ORM.Sample.Infra.EFCore.MySQL.Gen -o ../KLO128.D3ORM.Sample.Infra.EFCore.MySQL/Db -f --namespace KLO128.D3ORM.Sample.Infra.EFCore.MySQL.Db -f
  2. Update the input arguments (the paths and namespace names at the top of the text template script according to your project). 

        var targetPath = Host.ResolvePath("../../../KLO128.D3ORM.Sample.Domain/Models/Entities/");
        var entitiesJsonPath = Host.ResolvePath("EntitiesFromEFCore.tt").Replace(".tt", ".json");
        PropIdFormat = "{0}Id";
        DefaultNameSpace = "KLO128.D3ORM.Sample.Domain.Models.Entities";
        DatabaseContextNames = new string [] {"D3ORMSampleContext"};
        DefaultPropValues = new Dictionary<string, string> { { "LastChange", "DateTime.UtcNow" } };
  3. Modify EntitiesFromEFCore.json to reflect your entity aggregations or remove the file to persist all navigation properties. show me how... 
    1. D3ORM supports both side aggregations - each parent-child couple can have both navigation properties at the time (one to many and also "many to one"). D3ORM fills only one of them (avoiding the cyclic reference) with data according to a query. 
  4. Run the text template to Generate D3ORM entity classes from EF Core 6.0 entity classes. 

EntitiesFromEFCore-SQLiteFix.tt

  • If you use SQLite, you will probably have an issue with pure support of primitive data types from SQLite. This script can relieve the issue. 

  1. Update the input arguments (the paths and namespace names at the top of the text template script according to your project). 

        var targetProject = Host.ResolvePath("../../../KLO128.D3ORM.Sample.Domain/Models/Entities/");
  2. Run the script (in case of SQLite only). 

EntityDTOs.tt

  1. Update the input arguments (the paths and namespace names at the top of the text template script according to your project). 

        var targetPath = Host.ResolvePath("../../KLO128.D3ORM.Sample.Application.Contracts/DTOs/Entities/");
        var jsonConfigPath = Host.ResolvePath("EntityDTOs.tt").Replace(".tt", ".json");
        DefaultNameSpace = "KLO128.D3ORM.Sample.Application.Contracts.DTOs.Entities";
  2. Modify EntityDTOs.jsonshow me how... 
  3. Run the text template to generate DTO classes for entities. 

EntityPropMappings.tt

  1. Update the input arguments show me how... 

        PropKeyRegex = new Regex(@"[A-Za-z_][A-Za-z0-9_]+Id$");
        PropIdFormat = "{0}Id";
        DbIdFormat = "{0}_id";
        NameSpaceStr = "KLO128.D3ORM.Sample.Infra.D3ORM.MySQL";
        EntitiesNameSpace = "KLO128.D3ORM.Sample.Domain.Models.Entities";
        var sourceProjectFile = Host.ResolvePath("../KLO128.D3ORM.Sample.Domain/IQueryContainer.cs"); //any root file
  2. Run the text template to generate the core entity navigation and the core mappings between application and database names. 

Repositories-Ifaces.tt

  1. Update the input arguments (the paths and namespace names at the top of the text template script according to your project). 

        var targetPath = Host.ResolvePath("../../../KLO128.D3ORM.Sample.Domain/Repositories/");
        var entitiesJsonPath = Host.ResolvePath("EntitiesFromEFCore.tt").Replace(".tt", ".json");
        DefaultNameSpace = "KLO128.D3ORM.Sample.Domain.Repositories";
        EntitiesNameSpace = "KLO128.D3ORM.Sample.Domain.Models.Entities";
        DatabaseContextNames = new string [] {"D3ORMSampleContext"};

  1. Run the text template to generate repository interfaces for all entities. 

Repositories-Impl.tt

  1. Update the input arguments (the paths and namespace names at the top of the text template script according to your project). 

        var targetPath = Host.ResolvePath("../../../KLO128.D3ORM.Sample.Infra.D3ORM/Repositories/");
        var entitiesJsonPath = Host.ResolvePath("EntitiesFromEFCore.tt").Replace(".tt", ".json");
        DefaultNameSpace = "KLO128.D3ORM.Sample.Infra.D3ORM.Repositories";
        IfaceReposNameSpace = "KLO128.D3ORM.Sample.Domain.Repositories";
        EntitiesNameSpace = "KLO128.D3ORM.Sample.Domain.Models.Entities";
        DatabaseContextNames = new string [] {"D3ORMSampleContext"};

  1. Run the text template to generate repository implementations.