Requirement: .NET 6 (at least preview 5, where the Scaffold with nullable reference types feature landed and at least rc.2.21480.5 to work with the SQLPro Studio demo database)
- Create a new dummy project (required to run the
dotnet ef
CLI tool)
mkdir efscaffold && cd efscaffold
dotnet new classlib
rm Class1.cs
dotnet add package Microsoft.EntityFrameworkCore.Design
Using the .NET 6.0 SDK, <Nullable>enable</Nullable>
should be defined in the csproj file.
- Add the EF Core provider matching the database you want to scaffold. This example is for SQL Server:
dotnet add package Microsoft.EntityFrameworkCore.SqlServer
- Add the dotnet-ef CLI tool
dotnet new tool-manifest
dotnet tool install dotnet-ef
You can invoke the tool from this directory using the following commands: 'dotnet tool run dotnet-ef' or 'dotnet dotnet-ef'.
Tool 'dotnet-ef' (version '6.0.0') was successfully installed. Entry is added to the manifest file ~/efscaffold/.config/dotnet-tools.json.
- Scaffold your context and entities inside the Database directory
mkdir -p Database
dotnet ef dbcontext scaffold --verbose --force --output-dir Database --no-onconfiguring --context SqlProSampleContext "Server=sqlprosample.database.windows.net;Database=sqlprosample;User=sqlproro;Password=nh{Zd?*8ZU@Y}Bb#" Microsoft.EntityFrameworkCore.SqlServer