You signed in with another tab or window.Reload to refresh your session.You signed out in another tab or window.Reload to refresh your session.You switched accounts on another tab or window.Reload to refresh your session.Dismiss alert
A small Hello World sample project showing how to use MySQL with EF Core in a code-first approach.
The MySql database and tables will be automatically created tomatch the C# classes in the project (that's referrect to as "code first" EF). For reference, I've checked ina sampleMigrations folder that contains automatically generatedcode to create those tables, but you should use the commands belowto trivially generate your own custom database creation code.
Also, as a general note, if you are actively reading about MySQL and EF Core, you should note there are two MySQL to EFadapters, one from Oracle and one from the Pomelo Foundation. The syntax for the two is nearly the same but theycapitalize theUseMySql() method differently -UseMySQL() vsUseMySql(). That tripped me up more than I'd like to admitwhen I was first trying to stitch together examples from different sourcesto get this working.
Setup
First, edit the connection string inappsettings.json to have the desireddatabase name, username, and password.
Then, to create the database and tables, run the following commands before running this project.
This approach of creating the database and tables from C# classes is called "code-first". Thedotnet ef commands will create a folder calledMigrations, populate it with C# code thatwill create the database and tables that match the project, and then then run themigrations to create the database and tables, all under the directionof your connection string inappsettings.json. For reference, I've checked ina sample Migrations folder, but you should use the commands belowto create your own.