Transferred from: Https://www.jianshu.com/p/15a557ac43d9
1. Connect to MySQL
First step, create a new ASP. NET Core Project
New Project
This routine is a simple demonstration of the connection between the two databases, creating a new default Webapi project and adding the MySQL. NET core package to the current preview version. Note: Core 1.0 1.1 can be used with MySQL official, 2.0 will be the error suggested with Pomelo
MySQL 1.1
Pomelo 2.0
Then create a new code First database entity
Code First
Then write the configuration in the Startup.cs file
Startup.cs
Write the connection string in the Appsetting.json file, note that the string name must be the same as in the previous step, and Sslmode must be.
Appsetting.json
Next, write a simple method in the controller that queries the first data and then returns the JSON.
Apicontroller
The operation results are as follows
This is the result of running 2. The connection of MSSQL is similar to that of MySQL and needs to be installed
Support for. NET core 2.0 to modify the connection string.
ASP. NET core2.0 connect MySQL and MSSQL