The demo project is re-create the well-known Northwind sample database with .Net Core Entity framework technology, aka EF Core.
- .Net Core 2+
- .Net Core entity framework
- MySql 5.7+
- Ubuntu. You can choose Windows or Mac
- IDE : Visual Studio Code
-
The database is the same as my another repository db
-
Here I recap the ER diagram below
git clone https://github.com/harryho/dotnet-core-ef.git
-
If you don't update the database name to something else instead of Northwind, you can simply change the name "Northwind" in the file appsetting.json
-
E.g. You can change the name to NewDatabase as follow. Don't forget to replace user and password.
{
"connectionString": "Server=localhost;Database=NewDatabase;User=YourUserId;Password=YourPassword;"
}
## Remove the database
dotnet ef database drop --force
## Create an initial migration
dotnet ef migrations add --output-dir Data -p dotnet-demo-ef Initial
## To undo above action, use
dotnet ef migrations remove
## Create the database
dotnet ef database update
SELECT * FROM Northwind.__EFMigrationsHistory;
Database reversing is not within the scope of this project, but it is a tool for schema design at the very early stage. You can refine the schema on the database and reverse the update to .net core project
- Create a scaffolding code base from existing database, e.g. ExistingDatabase
dotnet ef dbcontext scaffold "Server=localhost;Database=ExistingDatabase;User=YourUserId;Password=YourPassword;" "Pomelo.EntityFrameworkCore.MySql"
# Reverse the whole database
dotnet ef dbcontext scaffold --force --output-dir Data "Server=localhost;Database=ExistingDatabase;User=YourUserId;Password=YourPassword;" "Pomelo.EntityFrameworkCore.MySql"
# Reverse the some tables
dotnet ef dbcontext scaffold --force --output-dir Data "Server=localhost;Database=ExistingDatabase;User=YourUserId;Password=YourPassword;" "Pomelo.EntityFrameworkCore.MySql" --tables table_001 table_002