You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+49-25Lines changed: 49 additions & 25 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,6 +1,6 @@
1
1
# Entity Framework Core Scaffolding with Handlebars
2
2
3
-
Scaffold EF Core models using Handlebars templates.
3
+
_Scaffold EF Core models using Handlebars templates._
4
4
5
5
- 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.
6
6
@@ -11,7 +11,16 @@ Before creating a pull request, please refer to the [Contributing Guidelines](ht
11
11
## Prerequisites
12
12
13
13
-[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).
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.
57
66
- Get help on _dotnet-ef-dbcontext-scaffold_ at the command line: `dotnet ef dbcontext scaffold -h`
58
67
- Execute the following command to reverse engineer classes from the NorthwindSlim database:
59
68
@@ -70,14 +79,35 @@ Before creating a pull request, please refer to the [Contributing Guidelines](ht
70
79
specific interfaces.
71
80
- When you run the _dotnet-ef-dbcontext-scaffold_ command again, you will see your updated reflected in the generated classes.
72
81
73
-
## Additional Partial Templates
82
+
## Nullable Reference Types
74
83
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.
76
85
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).
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
+
95
135
## Custom Template Data
96
136
97
137
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
0 commit comments