The project consists of the following sub-projects:
POS.Catalog.ApiPOS.Payment.ApiPOS.Data
Each service in the project (POS.Catalog.Api and POS.Payment.Api) has its own DbContext:
-
CatalogDbContext: This context is used byPOS.Catalog.Api. It's aware of and responsible for theProductsDbSet. -
PaymentDbContext: This context is used byPOS.Payment.Api. It's aware of and responsible for theTransactionsDbSet.
These two contexts are limited in scope and only handle their respective areas. They are not aware of the complete database schema.
The POSDbContext in POS.Data knows about the entire schema of the database and is responsible for managing the migrations and controlling the structure of the database.
In this project, migrations are controlled by the POSDbContext within the POS.Data project. The migrations can be run using the EF Core CLI tool or package manager console tools.
The migration process leverages an IDesignTimeDbContextFactory<> implementation within the POS.Data project, providing EF Core with the necessary information to set up the DbContext.
To add a new migration, perform the following steps:
- Open the terminal or command prompt.
- Navigate to the
POS.Dataproject directory. - Run the following command:
dotnet ef migrations add <MigrationName> --context POSDbContext
dotnet ef database update --context POSDbContextAdd-Migration -Name <MigrationName> -Context POSDbContext
Update-Database -Context POSDbContext