EntityFrameworkCore.Scaffolding.Handlebars 1.0.0-beta

Allows customization of classes reverse engineered from an existing database using the Entity Framework Core toolchain with Handlebars templates.

This is a prerelease version of EntityFrameworkCore.Scaffolding.Handlebars.
There is a newer version of this package available.
See the version list below for details.
Install-Package EntityFrameworkCore.Scaffolding.Handlebars -Version 1.0.0-beta
dotnet add package EntityFrameworkCore.Scaffolding.Handlebars --version 1.0.0-beta
<PackageReference Include="EntityFrameworkCore.Scaffolding.Handlebars" Version="1.0.0-beta" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add EntityFrameworkCore.Scaffolding.Handlebars --version 1.0.0-beta
The NuGet Team does not provide support for this client. Please contact its maintainers for support.
#r "nuget: EntityFrameworkCore.Scaffolding.Handlebars, 1.0.0-beta"
#r directive can be used in F# Interactive, C# scripting and .NET Interactive. Copy this into the interactive tool or source code of the script to reference the package.
// Install EntityFrameworkCore.Scaffolding.Handlebars as a Cake Addin
#addin nuget:?package=EntityFrameworkCore.Scaffolding.Handlebars&version=1.0.0-beta&prerelease

// Install EntityFrameworkCore.Scaffolding.Handlebars as a Cake Tool
#tool nuget:?package=EntityFrameworkCore.Scaffolding.Handlebars&version=1.0.0-beta&prerelease
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

Entity Framework Core Scaffolding with Handlebars

Scaffold EF Core models using Handlebars templates.

Prerequisites

Database Setup

  1. Use SQL Server Management Studio to connect to SQL Server
    • The easiest is to use LocalDb, which is installed with Visual Studio.
      Connect to: (localdb)\MsSqlLocalDb.
    • Create a new database named NorthwindSlim.
    • Download the data file from http://bit.ly/northwindslim.
    • Unzip NorthwindSlim.sql and run the script to create tables and populate them with data.

Usage

  1. Create a new .NET Core class library.

    Note: Using the EF Core toolchain with a .NET Standard class library is currently not supported. Instead, you can add a .NET Standard class library to the same solution as the .NET Core library, then add existing items and select Add As Link to include entity classes.

  2. Add EF Core SQL Server and Tools NuGet packages.
    Open the Package Manager Console, select the default project and enter:

    • Install-Package Microsoft.EntityFrameworkCore.SqlServer
    • Install-Package Microsoft.EntityFrameworkCore.Tools
  3. Edit the .csproj file to add the following section:

    <ItemGroup>
        <DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="2.0.0" />
    </ItemGroup>
    
    • Open a command prompt at the project location and run: dotnet restore.
  4. Add the EntityFrameworkCore.Scaffolding.Handlebars NuGet package:

    • Install-Package EntityFrameworkCore.Scaffolding.Handlebars -Pre
  5. Remove Class1.cs and add a ScaffoldingDesignTimeServices class.

    • Implement IDesignTimeServices by adding a ConfigureDesignTimeServices method
      that calls services.AddHandlebarsScaffolding.
    • You can optionally pass a ReverseEngineerOptions enum to indicate if you wish
      to generate only entity types, only a DbContext class, or both (which is the default).
    public class ScaffoldingDesignTimeServices : IDesignTimeServices
    {
        public void ConfigureDesignTimeServices(IServiceCollection services)
        {
            var options = ReverseEngineerOptions.DbContextAndEntities;
            services.AddHandlebarsScaffolding(options);
        }
    }
    
  6. Open a command prompt and use the EF .NET CLI tools to reverse engineer a context and models from an existing database.

    • Get help on dotnet-ef-dbcontext-scaffold at the command line: dotnet ef dbcontext scaffold -h
    • Execute the following command to reverse engineer classes from the NorthwindSlim database:
    dotnet ef dbcontext scaffold "Data Source=(localdb)\MSSQLLocalDB; Initial Catalog=NorthwindSlim; Integrated Security=True" Microsoft.EntityFrameworkCore.SqlServer -o Models -c NorthwindSlimContext -f
    
    • You should see context and/or entity classes appear in the Models folder of the project.
    • You will also see a CodeTemplates folder appear containing Handlebars templates for customizing generation of context and entity type classes.
    • Add -d to the command to use data annotations. You will need to add the System.ComponentModel.Annotations package to a .NET Standard library containing linked entity classes.
  7. You may edit any of the template files which appear under the CodeTemplates folder.

    • For now you can just add some comments, but you may wish to customize the templates in other ways, for example, by inheriting entities from a base class or implementing
      specific interfaces.
    • When you run the dotnet-ef-dbcontext-scaffold command again, you will see your updated reflected in the generated classes.

Entity Framework Core Scaffolding with Handlebars

Scaffold EF Core models using Handlebars templates.

Prerequisites

Database Setup

  1. Use SQL Server Management Studio to connect to SQL Server
    • The easiest is to use LocalDb, which is installed with Visual Studio.
      Connect to: (localdb)\MsSqlLocalDb.
    • Create a new database named NorthwindSlim.
    • Download the data file from http://bit.ly/northwindslim.
    • Unzip NorthwindSlim.sql and run the script to create tables and populate them with data.

Usage

  1. Create a new .NET Core class library.

    Note: Using the EF Core toolchain with a .NET Standard class library is currently not supported. Instead, you can add a .NET Standard class library to the same solution as the .NET Core library, then add existing items and select Add As Link to include entity classes.

  2. Add EF Core SQL Server and Tools NuGet packages.
    Open the Package Manager Console, select the default project and enter:

    • Install-Package Microsoft.EntityFrameworkCore.SqlServer
    • Install-Package Microsoft.EntityFrameworkCore.Tools
  3. Edit the .csproj file to add the following section:

    <ItemGroup>
        <DotNetCliToolReference Include="Microsoft.EntityFrameworkCore.Tools.DotNet" Version="2.0.0" />
    </ItemGroup>
    
    • Open a command prompt at the project location and run: dotnet restore.
  4. Add the EntityFrameworkCore.Scaffolding.Handlebars NuGet package:

    • Install-Package EntityFrameworkCore.Scaffolding.Handlebars -Pre
  5. Remove Class1.cs and add a ScaffoldingDesignTimeServices class.

    • Implement IDesignTimeServices by adding a ConfigureDesignTimeServices method
      that calls services.AddHandlebarsScaffolding.
    • You can optionally pass a ReverseEngineerOptions enum to indicate if you wish
      to generate only entity types, only a DbContext class, or both (which is the default).
    public class ScaffoldingDesignTimeServices : IDesignTimeServices
    {
        public void ConfigureDesignTimeServices(IServiceCollection services)
        {
            var options = ReverseEngineerOptions.DbContextAndEntities;
            services.AddHandlebarsScaffolding(options);
        }
    }
    
  6. Open a command prompt and use the EF .NET CLI tools to reverse engineer a context and models from an existing database.

    • Get help on dotnet-ef-dbcontext-scaffold at the command line: dotnet ef dbcontext scaffold -h
    • Execute the following command to reverse engineer classes from the NorthwindSlim database:
    dotnet ef dbcontext scaffold "Data Source=(localdb)\MSSQLLocalDB; Initial Catalog=NorthwindSlim; Integrated Security=True" Microsoft.EntityFrameworkCore.SqlServer -o Models -c NorthwindSlimContext -f
    
    • You should see context and/or entity classes appear in the Models folder of the project.
    • You will also see a CodeTemplates folder appear containing Handlebars templates for customizing generation of context and entity type classes.
    • Add -d to the command to use data annotations. You will need to add the System.ComponentModel.Annotations package to a .NET Standard library containing linked entity classes.
  7. You may edit any of the template files which appear under the CodeTemplates folder.

    • For now you can just add some comments, but you may wish to customize the templates in other ways, for example, by inheriting entities from a base class or implementing
      specific interfaces.
    • When you run the dotnet-ef-dbcontext-scaffold command again, you will see your updated reflected in the generated classes.

Release Notes

See: https://github.com/TrackableEntities/EntityFrameworkCore.Scaffolding.Handlebars/releases/tag/v1.0.0-beta1

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories (1)

Showing the top 1 popular GitHub repositories that depend on EntityFrameworkCore.Scaffolding.Handlebars:

Repository Stars
ErikEJ/EFCorePowerTools
Entity Framework Core Power Tools - reverse engineering, migrations and model visualization for EF Core

Version History

Version Downloads Last updated
5.0.2 1,999 2/19/2021
5.0.1 6,318 12/5/2020
5.0.0 553 11/15/2020
5.0.0-rc.2 559 10/18/2020
3.8.5 6,352 11/7/2020
3.8.4 8,240 9/28/2020
3.8.3 6,130 8/18/2020
3.8.2 2,018 7/21/2020
3.8.1 2,209 7/8/2020
3.7.0 13,600 5/1/2020
3.6.0 10,054 1/6/2020
3.5.1 1,309 12/15/2019
3.5.0 1,505 10/18/2019
3.0.0 408 10/14/2019
3.0.0-preview8 279 8/26/2019
2.1.1 22,026 8/5/2019
2.1.0 1,025 7/19/2019
2.0.0 3,596 6/25/2019
1.7.2 46,771 1/6/2019
1.7.1 559 1/5/2019
1.7.0 374 1/3/2019
1.6.0 810 12/17/2018
1.5.1 18,135 7/7/2018
1.5.0 692 6/22/2018
1.4.1 681 7/7/2018
1.4.0 534 6/23/2018
1.1.1 611 6/19/2018
1.1.0 662 6/3/2018
1.0.0 504 5/30/2018
1.0.0-rc3 695 5/26/2018
1.0.0-rc2 489 5/26/2018
1.0.0-rc 491 5/24/2018
1.0.0-beta 2,158 10/25/2017
Show less