9. Scaffold movie pages
Create the Scaffold movie pages
Use the scaffolding tool to produce Create
, Read
, Update
, and Delete
(CRUD) pages for the movie model.
Open a command window in the project directory. The project directory is the directory that contains the Program.cs
and .csproj
files.
Run the following command:
dotnet-aspnet-codegenerator controller -name MoviesController -m Movie -dc MvcMovieContext --relativeFolderPath Controllers --useDefaultLayout --referenceScriptLibraries -sqlite
The following table details the ASP.NET Core code generator parameters:
-m
The name of the model.
-dc
The data context.
--relativeFolderPath
The relative output folder path to create the files.
--useDefaultLayout|-udl
The default layout should be used for the views.
--referenceScriptLibraries
Adds _ValidationScriptsPartial
to Edit and Create pages.
-sqlite
Flag to specify if DbContext
should use SQLite instead of SQL Server.
Eliminate Warning for nullable.
To eliminate the warnings from nullable reference types, remove the following line from the MvcMovie.csproj
file:
<Nullable>enable</Nullable>
Initial migration
Step 1: If dotnet ef
has not been installed, install it as a global tool:
dotnet tool install --global dotnet-ef
For more information on the CLI for EF Core, see EF Core tools reference for .Net CLI.
Step 2: Run the following .NET CLI commands:
dotnet ef migrations add InitialCreate
dotnet ef database update
Test the app
Run the app and select the Movie App link.
dotnet watch
If you get an exception similar to the following, you may have missed the above Migration Step
Last updated