This project is a .NET Razor application that uses a MySQL database. It includes a simplified version of the Northwind database.
Here is a demo of the application:
- .NET SDK
- Docker
- MySQL
-
Clone the repository.
-
Navigate to the project directory.
-
Run the MySQL Docker container:
docker run --name=mysql1 -p 3306:3306 -e MYSQL_ROOT_PASSWORD=YOUR_PASSWORD -e MYSQL_DATABASE=mydatabase -d mysql:latest
This will start a new MySQL server in a Docker container. Make sure you replace
YOUR_PASSWORD
-
Connect to the MySQL server:
docker exec -it mysql1 mysql -uroot -p
When prompted, enter the root password (
YOUR_PASSWORD
) that you set when you started the MySQL server. -
Create the Northwind database:
CREATE DATABASE Northwind; USE Northwind; CREATE TABLE Orders ( OrderID int NOT NULL, ShipCountry varchar(15), Freight decimal(10,4), PRIMARY KEY (OrderID) ); INSERT INTO Orders (OrderID, ShipCountry, Freight) VALUES (10248, 'Germany', 32.38), (10249, 'Mexico', 11.61), (10250, 'Mexico', 65.83);
For stored procedure:
DELIMITER // CREATE PROCEDURE GetAverageFreight(IN shipCountry VARCHAR(15)) BEGIN SELECT AVG(Freight) FROM Orders WHERE ShipCountry = shipCountry; END // DELIMITER ;
This script creates a simplified version of the Northwind database with only the
Orders
table and a few sample records. -
Update the connection string in
appsettings.json
to point to your MySQL server. Make sure to replace<your_password>
with your actual password:"ConnectionStrings": { "DefaultConnection": "Server=localhost;Port=3306;Database=northwind;User=root;Password=<your_password>;" }
To run the application, use the dotnet watch
command:
dotnet watch
The application displays the average freight cost for a selected country in a selected currency. The freight cost is fetched from the database and converted to the selected currency when the page loads and whenever the selected country or currency changes.