Summary Files Commits Branches @commit @diff @stats
path: root / src / tutorials / connect-to-mysql-in-dotnet-ef
diff options
context:
space:
mode:
Commite7ac922aa3d097efc5fc9bd3a46bbc9f3b0bede8 (patch)
Author
 Syndamia <kamen.d.mladenov@protonmail.com>
2022-03-09 17:51:59 +0200
Committer
 Syndamia <kamen.d.mladenov@protonmail.com>
2022-03-09 17:51:59 +0200
Files25bb8d3d1a8aaa4fc5ce1ebcd8aacb193218a1c1 /src/tutorials/connect-to-mysql-in-dotnet-ef
syndamia.com-e7ac922aa3d097efc5fc9bd3a46bbc9f3b0bede8.tar
syndamia.com-e7ac922aa3d097efc5fc9bd3a46bbc9f3b0bede8.tar.gz
syndamia.com-e7ac922aa3d097efc5fc9bd3a46bbc9f3b0bede8.zip
Parent9f28a312879f4c92eeda3d4b27979bc322faa637 (diff)
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.md22
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
-[![🔗](/img/link-tabler.svg)](#NuGet%20packages)
+[![🔗](/img/link-tabler.svg)](#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
-[![🔗](/img/link-tabler.svg)](#Connection%20string)
+[![🔗](/img/link-tabler.svg)](#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
![MyServer root 127.0.0.1:3306](./img/connections.png) In this example, the user id is _root_ and the port is _3306_.
## Connecting
-[![🔗](/img/link-tabler.svg)](#Connecting)
+[![🔗](/img/link-tabler.svg)](#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
-[![🔗](/img/link-tabler.svg)](#ASP.NET%20Startup)
+[![🔗](/img/link-tabler.svg)](#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
-[![🔗](/img/link-tabler.svg)](#DBContext%20child%20class)
+[![🔗](/img/link-tabler.svg)](#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.