aspnetcore/data/scaffold_RP.md
The CLI tool, dotnet scaffold creates data access UI for many .NET project types, such as API, Aspire, Blazor, MVC, and Razor Pages. dotnet scaffold can be run interactively or as a command line tool via passing parameter values.
Install the .NET SDK.
The following command installs the scaffolder globally:
dotnet tool install --global Microsoft.dotnet-scaffold
See How to manage .NET tools for information on .NET tools and how to install them locally.
To launch the interactive tool, run dotnet scaffold. The UI changes as more features are added. Currently, the interactive UI looks similar to the following image:
To navigate the UI, use the:
If you have any problems with the following steps, see xref:tutorials/razor-pages/index?tabs=visual-studio-code.
dotnet new webapp -o MyWebApp
cd MyWebApp
Contact class to the MyWebApp project:
:::code language="csharp" source="~/data/scaffold_RP/samples/MyWebApp/Contact.cs":::dotnet scaffold in the MyWebApp folder and select Razor Pages, then enter return.ContactDbContext, then enter return.The dotnet scaffold tool makes the following changes to the project files:
Program.cs is updated to initialize the database connection.appsettings.json is updated with connection information.ContactDbContext.cs is created and added to the project root directory.The content has been generated but the database isn't initialized. Run the following commands to initialize the DB.
dotnet tool uninstall --global dotnet-ef
dotnet tool install --global dotnet-ef
dotnet ef migrations add initialMigration
dotnet ef database update
In The preceding commands:
dotnet tool uninstall --global dotnet-ef uninstalls the dotnet-ef tool. Uninstalling ensures the latest tool is successfully installed. If dotnet-ef isn't installed, an error messages A tool with the package Id 'dotnet-ef' could not be found. You can ignore this message.dotnet tool install --global dotnet-ef installs globally the dotnet-ef tool.dotnet ef migrations add initialMigration adds the initial migration. For more information, see xref:tutorials/razor-pages/model?tabs=visual-studio-code.dotnet ef database update applies the migrations to the database.Run the app:
dotnet run on the command line, which launches the app.wxyz is the port listed./ContactPages to the end of the URL.