Replace {ProjName} with your project's name
- In terminal, navigate to where you want your project folder
- In terminal, enter,
dotnet new mvc --no-https -o ProjNameDon't forget to change ProjName - In terminal, enter,
cd ProjName
- In terminal, in your project folder, enter
dotnet add package Pomelo.EntityFrameworkCore.MySql --version 3.1.1 - In terminal, in your project folder, enter
dotnet add package Microsoft.EntityFrameworkCore.Design --version 3.1.5This will add an installed package line to your .csproj file - In terminal, in your project folder, enter
code . - If a box that says, "Required assets are missing" click, "Yes" ONLY if we are opening the actual project folder, NOT the parent folder.
Copy and paste into the appsettings.json file. Don't forget to change YOUR-DB-NAME
{
"Logging": {
"LogLevel": {
"Default": "Information",
"Microsoft": "Warning",
"Microsoft.Hosting.Lifetime": "Information"
}
},
"AllowedHosts": "*",
"DBInfo": {
"Name": "MySqlConnect",
"ConnectionString": "server=localhost;userid=root;password=rootroot;port=3306;database=YOUR_DB_NAME;SslMode=None"
}
}
Create a new file under the Models project directory.
Name it, ProjNameContext.cs (but replace ProjName with your projects's name. For example, if your project name was, "CatFeeder", name the file, CatFeederContext.cs)
This file will direct the ORM to connect each DB table to the correct model/class.
Remember DbSet properties should be named in plural form. So if the model is Cat, the DbSet name should be Cats