To use a persistent SQL Server database locally, follow these steps:
- Install EF Core tools:
dotnet tool update --global dotnet-ef
- Configure Connection Strings: Ensure
appsettings.json contains valid connection strings pointing to your local SQL Server instance. - Apply Migrations: Open a command prompt in the
Web folder and execute:dotnet restore
dotnet tool restore
dotnet ef database update -c catalogcontext -p ../Infrastructure/Infrastructure.csproj -s Web.csproj
dotnet ef database update -c appidentitydbcontext -p ../Infrastructure/Infrastructure.csproj -s Web.csproj
This creates two databases: one for catalog/shopping cart data (catalogcontext) and one for user identity data (appidentitydbcontext).
Creating new migrations:
If you modify the models, use these commands from the Web folder:
# For Catalog
dotnet ef migrations add InitialModel --context catalogcontext -p ../Infrastructure/Infrastructure.csproj -s Web.csproj -o Data/Migrations
# For Identity
dotnet ef migrations add InitialIdentityModel --context appidentitydbcontext -p ../Infrastructure/Infrastructure.csproj -s Web.csproj -o Identity/Migrations
dotnet ef database update -c catalogcontext -p ../Infrastructure/Infrastructure.csproj -s Web.csproj
dotnet ef database update -c appidentitydbcontext -p ../Infrastructure/Infrastructure.csproj -s Web.csproj