Skip to content

Commit feb452c

Browse files
authored
Merge pull request #125 from TrackableEntities/update-net-3.1
Update to NET Core 3.1 SDK
2 parents 0f183d9 + 28067df commit feb452c

File tree

9 files changed

+73
-55
lines changed

9 files changed

+73
-55
lines changed

EntityFrameworkCore.Scaffolding.Handlebars.sln

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Scaffolding.Handlebars.Test
1313
EndProject
1414
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{7C70A676-4947-49A1-87CD-DB51F0E42056}"
1515
ProjectSection(SolutionItems) = preProject
16-
global.json = global.json
1716
LICENSE = LICENSE
1817
README.md = README.md
1918
EndProjectSection
@@ -26,9 +25,9 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ScaffoldingSample.Api", "sa
2625
EndProject
2726
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ScaffoldingSample.TypeScript", "sample\ScaffoldingSample.TypeScript\ScaffoldingSample.TypeScript.csproj", "{2713D6F6-6ADE-4E3F-8D07-30E19C14AD68}"
2827
EndProject
29-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "TemplatesAssembly", "sample\TemplatesAssembly\TemplatesAssembly.csproj", "{BA4575F5-1DDF-4E7D-A06E-09E56703C3FA}"
28+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "TemplatesAssembly", "sample\TemplatesAssembly\TemplatesAssembly.csproj", "{BA4575F5-1DDF-4E7D-A06E-09E56703C3FA}"
3029
EndProject
31-
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ScaffoldingSample.Embedded", "sample\ScaffoldingSample.Embedded\ScaffoldingSample.Embedded.csproj", "{9288FD98-43FC-4E6B-87FC-FC43E8071C07}"
30+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "ScaffoldingSample.Embedded", "sample\ScaffoldingSample.Embedded\ScaffoldingSample.Embedded.csproj", "{9288FD98-43FC-4E6B-87FC-FC43E8071C07}"
3231
EndProject
3332
Global
3433
GlobalSection(SolutionConfigurationPlatforms) = preSolution

README.md

Lines changed: 49 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# Entity Framework Core Scaffolding with Handlebars
22

3-
Scaffold EF Core models using Handlebars templates.
3+
_Scaffold EF Core models using Handlebars templates._
44

55
- Uses [Handlebars.NET](https://github.com/rexm/Handlebars.Net) to compile [Handlebars](http://handlebarsjs.com) templates when generating models with the [Entity Framework Core](https://github.com/aspnet/EntityFrameworkCore) scaffolding tools.
66

@@ -11,7 +11,16 @@ Before creating a pull request, please refer to the [Contributing Guidelines](ht
1111
## Prerequisites
1212

1313
- [Visual Studio 2019](https://www.visualstudio.com/downloads/) 16.4 or greater.
14-
- The .[NET Core 3.1 SDK](https://www.microsoft.com/net/download/core).
14+
- .[NET Core 3.1 SDK](https://www.microsoft.com/net/download/core).
15+
- [EF Core CLI](https://docs.microsoft.com/en-us/ef/core/miscellaneous/cli/dotnet).
16+
- Install global `dotnet-ef` tool.
17+
```
18+
dotnet tool install --global dotnet-ef
19+
```
20+
- Update global `dotnet-ef` tool.
21+
```
22+
dotnet tool update --global dotnet-ef
23+
```
1524
1625
## Database Setup
1726
@@ -53,7 +62,7 @@ Before creating a pull request, please refer to the [Contributing Guidelines](ht
5362
}
5463
```
5564
56-
5. Open a command prompt at the project level and use the **EF .NET Core CLI** tools to reverse engineer a context and models from an existing database.
65+
5. Open a command prompt at the project level and use the `dotnet ef` tool to reverse engineer a context and models from an existing database.
5766
- Get help on _dotnet-ef-dbcontext-scaffold_ at the command line: `dotnet ef dbcontext scaffold -h`
5867
- Execute the following command to reverse engineer classes from the NorthwindSlim database:
5968
@@ -70,14 +79,35 @@ Before creating a pull request, please refer to the [Contributing Guidelines](ht
7079
specific interfaces.
7180
- When you run the _dotnet-ef-dbcontext-scaffold_ command again, you will see your updated reflected in the generated classes.
7281
73-
## Additional Partial Templates
82+
## Nullable Reference Types
7483
75-
You can add new partial templates to one of the `Partials` folders, then reference with the usual Handlebars syntax. For example, a file named **Comment.hbs** can be referenced from **Class.hbs**.
84+
Take advantage of C# nullable reference types by enabling them in your .csproj file.
7685
77-
```hbs
78-
{{{> comment}}}
79-
public class {{class}}
86+
```xml
87+
<PropertyGroup>
88+
<TargetFramework>netcoreapp3.1</TargetFramework>
89+
<LangVersion>8.0</LangVersion>
90+
<Nullable>enable</Nullable>
91+
</PropertyGroup>
92+
```
93+
94+
Then enable nullable reference types for Handlebars scaffolding.
95+
96+
```csharp
97+
services.AddHandlebarsScaffolding(options =>
98+
{
99+
options.EnableNullableReferenceTypes = true;
100+
});
101+
```
102+
103+
Non-nullable properties will include the [null forgiving operator](https://docs.microsoft.com/en-us/dotnet/csharp/language-reference/operators/null-forgiving).
104+
105+
```csharp
106+
public partial class Product
80107
{
108+
public string ProductName { get; set; } = default!;
109+
public decimal? UnitPrice { get; set; }
110+
}
81111
```
82112

83113
## Excluded Tables
@@ -92,6 +122,16 @@ services.AddHandlebarsScaffolding(options =>
92122
});
93123
```
94124

125+
## Additional Partial Templates
126+
127+
You can add new partial templates to one of the `Partials` folders, then reference with the usual Handlebars syntax. For example, a file named **Comment.hbs** can be referenced from **Class.hbs**.
128+
129+
```hbs
130+
{{{> comment}}}
131+
public class {{class}}
132+
{
133+
```
134+
95135
## Custom Template Data
96136

97137
You may find it useful to add your own custom template data for use in your Handlebars templates. For example, the model namespace is not included by default in the `DbContext` class import statements. To compensate you may wish to add a `models-namespace` template to the **DbImports.hbs** template file.
@@ -174,7 +214,7 @@ public class ScaffoldingDesignTimeServices : IDesignTimeServices
174214
// Generate both context and entities
175215
options.ReverseEngineerOptions = ReverseEngineerOptions.DbContextAndEntities;
176216

177-
// Enable Nullable reference types Support https://docs.microsoft.com/en-us/ef/core/miscellaneous/nullable-reference-types
217+
// Enable Nullable reference types
178218
options.EnableNullableReferenceTypes = true;
179219

180220
// Put Models into folders by DB Schema
@@ -189,9 +229,6 @@ public class ScaffoldingDesignTimeServices : IDesignTimeServices
189229
{ "models-namespace", "ScaffoldingSample.Models" },
190230
{ "base-class", "EntityBase" }
191231
};
192-
193-
// Place models in folders by schema
194-
//options.EnableSchemaFolders = true;
195232
});
196233

197234
// Register Handlebars helper
@@ -271,16 +308,3 @@ public class ScaffoldingDesignTimeServices : IDesignTimeServices
271308
}
272309
}
273310
```
274-
275-
- You can also omit `c` and `--context-dir` arguments from the EF Core scaffolding command.
276-
277-
- Install the global `dotnet ef` tool.
278-
```
279-
dotnet tool install --global dotnet-ef --version 3.1.0-*
280-
```
281-
- Open a command prompt at the project root and execute:
282-
```
283-
dotnet ef dbcontext scaffold "Data Source=(localdb)\MSSQLLocalDB; Initial Catalog=NorthwindSlim; Integrated Security=True" Microsoft.EntityFrameworkCore.SqlServer -o Models -c NorthwindSlimContext -f --context-dir Contexts
284-
```
285-
286-

sample/ScaffoldingSample.Api/ScaffoldingSample.Api.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
<Project Sdk="Microsoft.NET.Sdk.Web">
22

33
<PropertyGroup>
4-
<TargetFramework>netcoreapp3.0</TargetFramework>
4+
<TargetFramework>netcoreapp3.1</TargetFramework>
55
<AspNetCoreHostingModel>InProcess</AspNetCoreHostingModel>
66
</PropertyGroup>
77

88
<ItemGroup>
9-
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.1.0" />
9+
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.1.5" />
1010
</ItemGroup>
1111

1212
<ItemGroup>

sample/ScaffoldingSample.Embedded/ScaffoldingSample.Embedded.csproj

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,13 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>netcoreapp3.0</TargetFramework>
4+
<TargetFramework>netcoreapp3.1</TargetFramework>
55
<LangVersion>latest</LangVersion>
66
</PropertyGroup>
77

88
<ItemGroup>
9-
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.1.0" />
10-
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="3.1.0">
11-
<PrivateAssets>all</PrivateAssets>
12-
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
13-
</PackageReference>
9+
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.1.5" />
10+
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="3.1.5" />
1411
</ItemGroup>
1512

1613
<ItemGroup>

sample/ScaffoldingSample.TypeScript/ScaffoldingSample.TypeScript.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>netcoreapp3.0</TargetFramework>
4+
<TargetFramework>netcoreapp3.1</TargetFramework>
55
<LangVersion>latest</LangVersion>
66
</PropertyGroup>
77

88
<ItemGroup>
9-
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.1.0" />
10-
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="3.1.0" />
9+
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.1.5" />
10+
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="3.1.5" />
1111
</ItemGroup>
1212

1313
<ItemGroup>

sample/ScaffoldingSample/ScaffoldingDesignTimeServices.cs

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,9 +44,6 @@ public void ConfigureDesignTimeServices(IServiceCollection services)
4444
{ "models-namespace", "ScaffoldingSample.Models" },
4545
{ "base-class", "EntityBase" }
4646
};
47-
48-
// Place models in folders by schema
49-
//options.EnableSchemaFolders = true;
5047
});
5148

5249
// Register Handlebars helper

sample/ScaffoldingSample/ScaffoldingSample.csproj

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>netcoreapp3.0</TargetFramework>
4+
<TargetFramework>netcoreapp3.1</TargetFramework>
55
<LangVersion>8.0</LangVersion>
66
<Nullable>enable</Nullable>
77
</PropertyGroup>
88

99
<ItemGroup>
10-
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.1.0" />
11-
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="3.1.0" />
10+
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.1.5" />
11+
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="3.1.5" />
1212
</ItemGroup>
1313

1414
<ItemGroup>

src/EntityFrameworkCore.Scaffolding.Handlebars/EntityFrameworkCore.Scaffolding.Handlebars.csproj

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<PropertyGroup>
44
<TargetFramework>netstandard2.1</TargetFramework>
55
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
6-
<PackageVersion>3.7.0</PackageVersion>
6+
<PackageVersion>3.8.0</PackageVersion>
77
<Authors>Tony Sneed</Authors>
88
<Company>Tony Sneed</Company>
99
<Title>Entity Framework Core Scaffolding with Handlebars</Title>
@@ -55,9 +55,10 @@
5555

5656
<ItemGroup>
5757
<PackageReference Include="Handlebars.Net" Version="1.10.1" />
58-
<PackageReference Include="Humanizer.Core" Version="2.8.2" />
59-
<PackageReference Include="JetBrains.Annotations" Version="2019.1.3" />
60-
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="3.1.0" />
58+
<PackageReference Include="Humanizer.Core" Version="2.8.26" />
59+
<PackageReference Include="JetBrains.Annotations" Version="2020.1.0" />
60+
<PackageReference Include="Microsoft.EntityFrameworkCore.Abstractions" Version="3.1.5" />
61+
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="3.1.5" />
6162
</ItemGroup>
6263

6364
<ItemGroup>

test/Scaffolding.Handlebars.Tests/Scaffolding.Handlebars.Tests.csproj

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<Project Sdk="Microsoft.NET.Sdk">
22

33
<PropertyGroup>
4-
<TargetFramework>netcoreapp3.0</TargetFramework>
4+
<TargetFramework>netcoreapp3.1</TargetFramework>
55
<IsPackable>false</IsPackable>
66
<LangVersion>latest</LangVersion>
77
</PropertyGroup>
@@ -11,12 +11,12 @@
1111
</ItemGroup>
1212

1313
<ItemGroup>
14-
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="3.1.0"/>
15-
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="3.1.0" />
16-
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.1.0" />
17-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.4.0" />
14+
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="3.1.5" />
15+
<PackageReference Include="Microsoft.EntityFrameworkCore.Sqlite" Version="3.1.5" />
16+
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.1.5" />
17+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="16.6.1" />
1818
<PackageReference Include="xunit" Version="2.4.1" />
19-
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.1" />
19+
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.2" />
2020
</ItemGroup>
2121

2222
<ItemGroup>

0 commit comments

Comments
 (0)