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: aspnetcore/blazor/tutorials/movie-database-app/part-1.md
+2-1Lines changed: 2 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -304,7 +304,8 @@ if (!app.Environment.IsDevelopment())
304
304
By default, an ASP.NET Core app doesn't provide a status code page for HTTP error status codes, such as *404 - Not Found*. When the app sets an HTTP 400-599 error status code without a body, it returns the status code and an empty response body. However, an app generated from the Blazor Web App project template calls <xref:Microsoft.AspNetCore.Builder.StatusCodePagesExtensions.UseStatusCodePagesWithReExecute%2A> to add Status Code Pages Middleware to the request pipeline for pages that aren't found, which generates the response body by re-executing the request pipeline using the path to the Not Found error page (`/not-found`):
Copy file name to clipboardExpand all lines: aspnetcore/blazor/tutorials/movie-database-app/part-2.md
+116-7Lines changed: 116 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,5 +1,6 @@
1
1
---
2
2
title: Build a Blazor movie database app (Part 2 - Add and scaffold a model)
3
+
ai-usage: ai-assisted
3
4
author: guardrex
4
5
description: This part of the Blazor movie database app tutorial explains how to add a movie class to the app and scaffold the database and UI from the movie class.
5
6
monikerRange: '>= aspnetcore-8.0'
@@ -113,9 +114,21 @@ Select **Build** > **Build Solution** from the menu bar or press <kbd>F6</kbd> o
113
114
114
115
## Add Nuget packages and tools
115
116
116
-
To add the required NuGet packages and tools, execute the following .NET CLI commands in the **Terminal** (**Terminal** menu > **New Terminal**).
117
+
:::moniker range=">= aspnetcore-9.0"
117
118
118
-
Paste all of the following commands at the prompt (`>`) of the **Terminal**. When you paste multiple commands, a warning appears stating that multiple commands will execute. Dismiss the warning and proceed with the paste operation.
119
+
To add the `dotnet scaffold` tool, execute the following .NET CLI command in the **Terminal** (**Terminal** menu > **New Terminal**) opened to the project's root folder:
To add the required NuGet packages and tools, execute the following .NET CLI commands in the **Terminal** (**Terminal** menu > **New Terminal**) opened to the project's root folder.
130
+
131
+
Paste all of the following commands at the prompt (`>`) of the **Terminal**. When you paste multiple commands, a warning may appear stating that multiple commands will execute. Dismiss the warning and proceed with the paste operation.
119
132
120
133
When you paste multiple commands, all of the commands execute except the last one. The last command doesn't execute until you press <kbd>Enter</kbd> on the keyboard.
> The preceding commands are .NET CLI commands, and .NET CLI commands are executed when entered at a [PowerShell](/powershell/) prompt, which is the default command shell of the VS Code **Terminal**.
139
152
140
-
Save the project file.
141
-
142
153
The preceding commands add:
143
154
144
155
*[Command-line interface (CLI) tools for EF Core](/ef/core/miscellaneous/cli/dotnet).
@@ -148,6 +159,10 @@ The preceding commands add:
148
159
*[`Microsoft.VisualStudio.Web.CodeGeneration.Design`](https://www.nuget.org/packages/Microsoft.VisualStudio.Web.CodeGeneration.Design) for scaffolding.
149
160
*[`Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore`](https://www.nuget.org/packages/Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore) to use the <xref:Microsoft.Extensions.DependencyInjection.DatabaseDeveloperPageExceptionFilterServiceExtensions.AddDatabaseDeveloperPageExceptionFilter%2A> extension method in the `Program` file, which captures database-related exceptions.
150
161
162
+
:::moniker-end
163
+
164
+
Save any open files.
165
+
151
166
In the **Command Palette** (<kbd>Ctrl</kbd>+<kbd>Shift</kbd>+<kbd>P</kbd>), use the `.NET: Build` command to build the app.
152
167
153
168
Confirm that the app built successfully.
@@ -158,9 +173,21 @@ Confirm that the app built successfully.
158
173
159
174
## Add Nuget packages and tools
160
175
176
+
:::moniker range=">= aspnetcore-9.0"
177
+
178
+
To add the `dotnet scaffold` tool, execute the following .NET CLI command in a command shell opened to the project's root folder:
To add the required NuGet packages and tools, execute the following .NET CLI commands in a command shell opened to the project's root folder.
162
189
163
-
Paste all of the following commands at the prompt (`>`) of the command shell. When you paste multiple commands, a warning appears stating that multiple commands will execute. Dismiss the warning and proceed with the paste operation.
190
+
Paste all of the following commands at the prompt (`>`) of the command shell. When you paste multiple commands, a warning may appear stating that multiple commands will execute. Dismiss the warning and proceed with the paste operation.
164
191
165
192
When you paste multiple commands, all of the commands execute except the last one. The last command doesn't execute until you press <kbd>Enter</kbd> on the keyboard.
*[Command-line interface (CLI) tools for EF Core](/ef/core/miscellaneous/cli/dotnet).
@@ -187,6 +212,10 @@ The preceding commands add:
187
212
*[`Microsoft.VisualStudio.Web.CodeGeneration.Design`](https://www.nuget.org/packages/Microsoft.VisualStudio.Web.CodeGeneration.Design) for scaffolding.
188
213
*[`Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore`](https://www.nuget.org/packages/Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore) to use the <xref:Microsoft.Extensions.DependencyInjection.DatabaseDeveloperPageExceptionFilterServiceExtensions.AddDatabaseDeveloperPageExceptionFilter%2A> extension method in the `Program` file, which captures database-related exceptions.
189
214
215
+
:::moniker-end
216
+
217
+
Save any open files.
218
+
190
219
In a command shell opened to the project's root folder, execute the [`dotnet build`](/dotnet/core/tools/dotnet-build) command:
191
220
192
221
```dotnetcli
@@ -230,6 +259,44 @@ Complete the **Add Razor Components using Entity Framework (CRUD)** dialog:
230
259
231
260
In the **Terminal** (**Terminal** menu > **New Terminal**) opened to the project's root directory, execute the following command. SQLite is used as the database for users adopting VS Code tooling for this tutorial series.
232
261
262
+
:::moniker range=">= aspnetcore-9.0"
263
+
264
+
```dotnetcli
265
+
dotnet scaffold
266
+
```
267
+
268
+
When the initializing prompt appears, press <kbd>Enter</kbd> on the keyboard.
269
+
270
+
For the **Scaffolding Category**, use the arrow keys to select **Blazor**. Press <kbd>Enter</kbd>.
271
+
272
+
For the **Command Name**, use the arrow keys to select **Razor Components with EntityFrameworkCore (CRUD)**. Press <kbd>Enter</kbd>.
273
+
274
+
*CRUD* is an acronym for Create, Read, Update, and Delete. The scaffolder produces create, edit, delete, details, and index components for the app.
275
+
276
+
For the **.NET project file**, press <kbd>Enter</kbd> to accept the app's project file (`BlazorWebAppMovies.csproj`).
277
+
278
+
For the **Model Name**, confirm that **Movie** (`Movie` class) is selected. Press <kbd>Enter</kbd>.
279
+
280
+
For the **Data Context Class**, type `BlazorWebAppMoviesContext`. Press <kbd>Enter</kbd>.
281
+
282
+
For the **Database Provider**, use the arrow keys to select **sqlite-efcore**. Press <kbd>Enter</kbd>.
283
+
284
+
For **Page**, confirm that **CRUD** is selected. Press <kbd>Enter</kbd>.
285
+
286
+
When prompted to include prerelease packages, use the arrow keys to select **No**. Press <kbd>Enter</kbd>.
287
+
288
+
Executing the `dotnet scaffold` command adds the following tools and packages to the app:
289
+
290
+
*[Command-line interface (CLI) tools for EF Core](/ef/core/miscellaneous/cli/dotnet).
* The SQLite provider with the EF Core package as a dependency.
294
+
*[`Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore`](https://www.nuget.org/packages/Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore) to use the <xref:Microsoft.Extensions.DependencyInjection.DatabaseDeveloperPageExceptionFilterServiceExtensions.AddDatabaseDeveloperPageExceptionFilter%2A> extension method in the `Program` file, which captures database-related exceptions.
@@ -243,12 +310,52 @@ The following table details the ASP.NET Core code generator options used in the
243
310
*`-m`: The name of the model.
244
311
*`-outDir`: The output directory for the generated components. A folder is created from the model name in the output directory to hold the components (for example, `MoviePages` in this case).
245
312
313
+
:::moniker-end
314
+
246
315
:::zone-end
247
316
248
317
:::zone pivot="cli"
249
318
250
319
In a command shell opened to the project's root folder, execute the following command. SQLite is used as the database for users adopting .NET CLI tooling for this tutorial series.
251
320
321
+
:::moniker range=">= aspnetcore-9.0"
322
+
323
+
```dotnetcli
324
+
dotnet scaffold
325
+
```
326
+
327
+
When the initializing prompt appears, press <kbd>Enter</kbd> on the keyboard.
328
+
329
+
For the **Scaffolding Category**, use the arrow keys to select **Blazor**. Press <kbd>Enter</kbd>.
330
+
331
+
For the **Command Name**, use the arrow keys to select **Razor Components with EntityFrameworkCore (CRUD)**. Press <kbd>Enter</kbd>.
332
+
333
+
*CRUD* is an acronym for Create, Read, Update, and Delete. The scaffolder produces create, edit, delete, details, and index components for the app.
334
+
335
+
For the **.NET project file**, press <kbd>Enter</kbd> to accept the app's project file (`BlazorWebAppMovies.csproj`).
336
+
337
+
For the **Model Name**, confirm that **Movie** (`Movie` class) is selected. Press <kbd>Enter</kbd>.
338
+
339
+
For the **Data Context Class**, type `BlazorWebAppMoviesContext`. Press <kbd>Enter</kbd>.
340
+
341
+
For the **Database Provider**, use the arrow keys to select **sqlite-efcore**. Press <kbd>Enter</kbd>.
342
+
343
+
For **Page**, confirm that **CRUD** is selected. Press <kbd>Enter</kbd>.
344
+
345
+
When prompted to include prerelease packages, use the arrow keys to select **No**. Press <kbd>Enter</kbd>.
346
+
347
+
Executing the `dotnet scaffold` command adds the following tools and packages to the app:
348
+
349
+
*[Command-line interface (CLI) tools for EF Core](/ef/core/miscellaneous/cli/dotnet).
* The SQLite provider with the EF Core package as a dependency.
353
+
*[`Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore`](https://www.nuget.org/packages/Microsoft.AspNetCore.Diagnostics.EntityFrameworkCore) to use the <xref:Microsoft.Extensions.DependencyInjection.DatabaseDeveloperPageExceptionFilterServiceExtensions.AddDatabaseDeveloperPageExceptionFilter%2A> extension method in the `Program` file, which captures database-related exceptions.
@@ -262,6 +369,8 @@ The following table details the ASP.NET Core code generator options used in the
262
369
*`-m`: The name of the model.
263
370
*`-outDir`: The output directory for the generated components. A folder is created from the model name in the output directory to hold the components (for example, `MoviePages` in this case).
264
371
372
+
:::moniker-end
373
+
265
374
:::zone-end
266
375
267
376
The `appsettings.json` file is updated with the connection string used to connect to a local database. In the following example, the `{CONNECTION STRING}` is the connection string automatically generated by the scaffolder:
0 commit comments