1: Create an EF class library Install 2 packs
①Microsoft.EntityFrameworkCore.Tools
(2) Pomelo.EntityFrameworkCore.MySql (this is a third-party ef mysql middleware)
2. To generate the database entity and EF's DBcontext object, use the Scaffold-DBcontext command
Enter the following command in the package console
server: database address, user id: account, password: login password If it is an update for a single table, add a -tables followed by the name of the table to be updated
After the execution is completed, the specified Model will be generated, note: the table must have a primary key before it will be generated, if there is no host to report the Unable to generate entity type for table "xxxx" warning, of course the entity will not be generated
If you do not generate the model in the second step above and execute the program directly, an error will be prompted, and the error is
“Error: the entity type requires a primary key”
3: Create a standard web application and use it
(1) Configure the address information of the database in appsettings.json, and pay attention to SslModel=none for example
(2) In startup.cs configuration injection, there are some references that are useful
(3) After that, there are standard calls, such as use in controllers
This is the basic EF core mysql starter configuration.
No matter how awesome ---- dream is, it can't resist my stupid persistence! Don't be at the age when you should struggle, and be greedy for comfort. Learn more today, and tomorrow the road will be wider!
|