diff options
Updated all id links with new format, following update to ssg6
1 files changed, 11 insertions, 11 deletions
| -rw-r--r-- | src/tutorials/connect-to-mysql-in-dotnet-ef/index.md | 22 |
diff --git a/src/tutorials/connect-to-mysql-in-dotnet-ef/index.md b/src/tutorials/connect-to-mysql-in-dotnet-ef/index.md index 4b3a5da..54048c3 100644 --- a/src/tutorials/connect-to-mysql-in-dotnet-ef/index.md +++ b/src/tutorials/connect-to-mysql-in-dotnet-ef/index.md @@ -14,19 +14,19 @@ Also, [MySql.Data.EntityFrameworkCore](https://www.nuget.org/packages/MySql.Data ## Contents <div></div> -1. [NuGet packages](#NuGet%20packages) -2. [Connection string](#Connection%20string) -3. [Connecting](#Connecting) - 1. [ASP.NET Startup](#ASP.NET%20Startup) - 2. [DBContext child class](#DBContext%20child%20class) +1. [NuGet packages](#nuget-packages) +2. [Connection string](#connection-string) +3. [Connecting](#connecting) + 1. [ASP.NET Startup](#asp.net-startup) + 2. [DBContext child class](#dbcontext-child-class) ## NuGet packages -[](#NuGet%20packages) +[](#nuget-packages) You'll need to install [Pomelo.EntityFrameworkCore.MySql](https://www.nuget.org/packages/Pomelo.EntityFrameworkCore.MySql/). It provides the stuff necessary for connecting and using a `MySql` database. ## Connection string -[](#Connection%20string) +[](#connection-string) There are [a lot](https://www.connectionstrings.com/mysql/) of ways to setup the connection string but I've found that this one works the best: @@ -39,9 +39,9 @@ If you are using `MySQL Workbench` and you don't know your port and id, you can  In this example, the user id is _root_ and the port is _3306_. ## Connecting -[](#Connecting) +[](#connecting) -To connect, you'll need to call the `UseMySql` method, either in [ASP.NET Startup](#ASP.NET%20Startup) or in a [DBContext child class](#DBContext%20child%20class). +To connect, you'll need to call the `UseMySql` method, either in [ASP.NET Startup](#asp.net-startup) or in a [DBContext child class](#dbcontext-child-class). The method requires at least two arguments: connection string and `MySql` server version. The latter you can find, by going to the `Help/About Workbench` window inside `MySQL Workbench`. @@ -56,7 +56,7 @@ For the server version argument, create a new object of type `MySqlServerVersion Where `CONNECTION_STRING` is a (constant) variable that contains your connection string, and 8, 0, 21 are the version numbers. ### ASP.NET Startup -[](#ASP.NET%20Startup) +[](#asp.net-startup) For `ASP.NET` applications, the connection must be put inside the `ConfigureServices` method of the `Startup.cs` file. If you already have a `.UseSQL` method call in there, just replace it with your `.UseMySql` method and arguments. @@ -74,7 +74,7 @@ The result should look something along the lines of: <p></p> ### DBContext child class -[](#DBContext%20child%20class) +[](#dbcontext-child-class) Another way to connect is via a `DBContext` child class (so, inside your own DB context). Just, override the `OnConfiguring` method and call the `.UseMySql` method from the `optionsBuilder` parameter. |