Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 5 additions & 8 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ Scaffold EF Core models using Handlebars templates.

## Prerequisites

- [Visual Studio 2017](https://www.visualstudio.com/downloads/) 15.8 or greater.
- The .[NET Core 2.1 SDK](https://www.microsoft.com/net/download/core) (version 2.1.3 or greater).
- [Visual Studio 2017](https://www.visualstudio.com/downloads/) 15.9 or greater.
- The .[NET Core 2.2 SDK](https://www.microsoft.com/net/download/core) (version 2.2.100 or greater).

## Database Setup

Expand All @@ -21,14 +21,14 @@ Scaffold EF Core models using Handlebars templates.
## Usage

1. Create a new **.NET Core** class library.
- If necessary, edit the csproj file to update the **TargetFramework** to 2.1.
- If necessary, edit the csproj file to update the **TargetFramework** to 2.2.

> **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`
- If needed update EF Core to version 2.1.
- If needed update EF Core to version 2.2.

3. Add the **EntityFrameworkCore.Scaffolding.Handlebars** NuGet package:
- `Install-Package EntityFrameworkCore.Scaffolding.Handlebars`
Expand Down Expand Up @@ -86,10 +86,7 @@ public class ScaffoldingDesignTimeServices : IDesignTimeServices
var myHelper = (helperName: "my-helper", helperFunction: (Action<TextWriter, object, object[]>) MyHbsHelper);

// Add Handlebars scaffolding templates
services.AddHandlebarsScaffolding(options);

// Register Handlebars helper
services.AddHandlebarsHelpers(myHelper);
services.AddHandlebarsScaffolding(options, myHelper);
}

// Sample Handlebars helper
Expand Down
2 changes: 1 addition & 1 deletion global.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"sdk": {
"version": "2.1.300-*"
"version": "2.2.100"
}
}
8 changes: 6 additions & 2 deletions sample/ScaffoldingSample/Contexts/NorthwindSlimContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)

protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.HasAnnotation("ProductVersion", "2.2.0-rtm-35687");

modelBuilder.Entity<Category>(entity =>
{
entity.Property(e => e.CategoryName)
Expand All @@ -62,7 +64,8 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)

modelBuilder.Entity<CustomerSetting>(entity =>
{
entity.HasKey(e => e.CustomerId);
entity.HasKey(e => e.CustomerId)
.HasName("PK_dbo.CustomerSetting");

entity.Property(e => e.CustomerId)
.HasMaxLength(5)
Expand Down Expand Up @@ -100,7 +103,8 @@ protected override void OnModelCreating(ModelBuilder modelBuilder)

modelBuilder.Entity<EmployeeTerritories>(entity =>
{
entity.HasKey(e => new { e.EmployeeId, e.TerritoryId });
entity.HasKey(e => new { e.EmployeeId, e.TerritoryId })
.HasName("PK_dbo.EmployeeTerritories");

entity.Property(e => e.TerritoryId).HasMaxLength(20);

Expand Down
9 changes: 3 additions & 6 deletions sample/ScaffoldingSample/Sample.ReadMe.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ Demonstrates how to reverse engineer an existing database using the EF Core tool

## Prerequisites

- [Visual Studio 2017](https://www.visualstudio.com/downloads/) 15.8 or greater.
- The .[NET Core 2.1 SDK](https://www.microsoft.com/net/download/core) (version 2.1.3 or greater).
- [Visual Studio 2017](https://www.visualstudio.com/downloads/) 15.9 or greater.
- The .[NET Core 2.2 SDK](https://www.microsoft.com/net/download/core) (version 2.2.100 or greater).

## Database Setup

Expand All @@ -32,10 +32,7 @@ public class ScaffoldingDesignTimeServices : IDesignTimeServices
var myHelper = (helperName: "my-helper", helperFunction: (Action<TextWriter, object, object[]>) MyHbsHelper);

// Add Handlebars scaffolding templates
services.AddHandlebarsScaffolding(options);

// Register Handlebars helper
services.AddHandlebarsHelpers(myHelper);
services.AddHandlebarsScaffolding(options, myHelper);
}

// Sample Handlebars helper
Expand Down
5 changes: 1 addition & 4 deletions sample/ScaffoldingSample/ScaffoldingDesignTimeServices.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,7 @@ public void ConfigureDesignTimeServices(IServiceCollection services)
var myHelper = (helperName: "my-helper", helperFunction: (Action<TextWriter, object, object[]>) MyHbsHelper);

// Add Handlebars scaffolding templates
services.AddHandlebarsScaffolding(options);

// Register Handlebars helper
services.AddHandlebarsHelpers(myHelper);
services.AddHandlebarsScaffolding(options, myHelper);
}

// Sample Handlebars helper
Expand Down
6 changes: 3 additions & 3 deletions sample/ScaffoldingSample/ScaffoldingSample.csproj
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>netcoreapp2.0</TargetFramework>
<TargetFramework>netcoreapp2.2</TargetFramework>
<LangVersion>latest</LangVersion>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="2.1.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.1.1" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="2.2.0" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.2.0" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PackageVersion>1.6.0</PackageVersion>
<PackageVersion>1.6.1</PackageVersion>
<Authors>Tony Sneed</Authors>
<Company>Tony Sneed</Company>
<Title>Entity Framework Core Scaffolding with Handlebars</Title>
Expand All @@ -17,7 +17,7 @@
<IncludeSource>true</IncludeSource>
<SignAssembly>true</SignAssembly>
<AssemblyOriginatorKeyFile>key.snk</AssemblyOriginatorKeyFile>
<Version>1.6.0</Version>
<Version>1.6.1</Version>
</PropertyGroup>

<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|AnyCPU'">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,11 @@ public static class ServiceCollectionExtensions
/// </summary>
/// <param name="services"> The <see cref="IServiceCollection" /> to add services to. </param>
/// <param name="options">Options for reverse engineering classes from an existing database.</param>
/// <param name="handlebarsHelpers">Handlebars helpers.</param>
/// <returns>The same service collection so that multiple calls can be chained.</returns>
public static IServiceCollection AddHandlebarsScaffolding(this IServiceCollection services,
ReverseEngineerOptions options = ReverseEngineerOptions.DbContextAndEntities)
ReverseEngineerOptions options = ReverseEngineerOptions.DbContextAndEntities,
params (string helperName, Action<TextWriter, object, object[]> helperFunction)[] handlebarsHelpers)
{
Type dbContextGeneratorImpl;
var dbContextGeneratorType = typeof(ICSharpDbContextGenerator);
Expand Down Expand Up @@ -63,6 +65,7 @@ public static IServiceCollection AddHandlebarsScaffolding(this IServiceCollectio
{
{Constants.SpacesHelper, HandlebarsHelpers.SpacesHelper}
};
handlebarsHelpers.ToList().ForEach(h => helpers.Add(h.helperName, h.helperFunction));
return new HbsHelperService(helpers);
});
return services;
Expand All @@ -77,6 +80,7 @@ public static IServiceCollection AddHandlebarsScaffolding(this IServiceCollectio
/// <param name="services"> The <see cref="IServiceCollection" /> to add services to. </param>
/// <param name="handlebarsHelpers">Handlebars helpers.</param>
/// <returns>The same service collection so that multiple calls can be chained.</returns>
[Obsolete("AddHandlebarsHelpers has been deprecated. Pass helpers to AddHandlebarsScaffolding instead.")]
public static IServiceCollection AddHandlebarsHelpers(this IServiceCollection services,
params (string helperName, Action<TextWriter, object, object[]> helperFunction)[] handlebarsHelpers)
{
Expand Down