This sample creates the KitchenPC schema in an empty PostgreSQL database and imports the bundled
SampleData/KPCData.xml snapshot. The result contains the ingredient catalog, ingredient forms,
natural-language parsing data, and a small collection of recipes needed by the Web API sample.
The tool demonstrates database provisioning with two KitchenPC contexts:
- A
StaticContextloadsKPCData.xmlinto memory. - A
DBContextconnects to PostgreSQL. DBContext.InitializeStore()creates the KitchenPC schema.DBContext.Import(staticContext)copies the static data into PostgreSQL.
Warning:
InitializeStore()recreates the KitchenPC schema. Running this tool against an existing KitchenPC database deletes its existing KitchenPC tables and data. Use a dedicated, newly created sample database.
- .NET 10 SDK
- Docker
- A PostgreSQL client (
psql), either locally installed or run inside the container
The following starts PostgreSQL 17 in a Docker container and exposes it on local port 5432:
docker run --name kitchenpc-postgres \
--detach \
--env POSTGRES_PASSWORD=postgres \
--publish 5432:5432 \
postgres:17If the container already exists but is stopped, restart it instead:
docker start kitchenpc-postgresRun psql in the container to create the blank KPCSample database:
docker exec -it kitchenpc-postgres \
psql --username postgres --command 'CREATE DATABASE "KPCSample";'The initializer creates tables, not the database itself. If KPCSample already exists and you
want a clean start, drop and recreate it explicitly before continuing.
From the Samples repository root, put the development connection string in an environment variable. This avoids placing the password in source control or passing it in shell history:
export KITCHENPC_CONNECTION_STRING='Host=localhost;Port=5432;Database=KPCSample;Username=postgres;Password=postgres'Use the hostname, published port, username, and password appropriate for your PostgreSQL setup.
Run the initializer:
dotnet run --project DatabaseInitializer/DatabaseInitializer.csprojThe program displays a destructive-operation warning. Type PROVISION to proceed. For an
unattended development setup, pass --yes after the -- argument separator:
dotnet run --project DatabaseInitializer/DatabaseInitializer.csproj -- --yesSuccessful output reports how many ingredients and recipes were loaded, creates the schema, and imports the sample data. Rerunning the initializer recreates the schema and replaces all data.
List the KitchenPC tables:
docker exec -it kitchenpc-postgres \
psql --username postgres --dbname KPCSample --command '\dt'Check the imported row counts:
docker exec -it kitchenpc-postgres \
psql --username postgres --dbname KPCSample \
--command 'SELECT COUNT(*) AS ingredients FROM shoppingingredients; SELECT COUNT(*) AS recipes FROM recipes;'shoppingingredients is the legacy KitchenPC schema name for the main ingredient catalog.
Give the web application the same connection string through .NET user secrets:
dotnet user-secrets set \
--project WebApp/WebApp.csproj \
"ConnectionStrings:KPCContext" \
"$KITCHENPC_CONNECTION_STRING"Then run it:
dotnet run --project WebApp/WebApp.csprojSee the WebApp README for frontend setup and usage details.
--connection-string <value> Override KITCHENPC_CONNECTION_STRING.
--data-directory <path> Use another directory containing KPCData.xml.
--yes Skip interactive confirmation.
-h, --help Display command help.
Prefer the environment variable over --connection-string, because command-line arguments can
be visible in process listings and shell history.