This article is a mirror article of machine translation, please click here to jump to the original article.

View: 18080|Reply: 0

[.NET Core] . NetCore tutorial EFCore connects to Mysql DBFirst mode

[Copy link]
Posted on 2/6/2019 9:54:32 AM | | |
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!






Previous:Where is the package manager console?
Next:c# Winform/WPF
Disclaimer:
All software, programming materials or articles published by Code Farmer Network are only for learning and research purposes; The above content shall not be used for commercial or illegal purposes, otherwise, users shall bear all consequences. The information on this site comes from the Internet, and copyright disputes have nothing to do with this site. You must completely delete the above content from your computer within 24 hours of downloading. If you like the program, please support genuine software, purchase registration, and get better genuine services. If there is any infringement, please contact us by email.

Mail To:help@itsvse.com