Skip to content

Commit 28067df

Browse files
committed
Update ReadMe to include latest features.
1 parent 6b987ae commit 28067df

File tree

2 files changed

+49
-28
lines changed

2 files changed

+49
-28
lines changed

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/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

0 commit comments

Comments
 (0)