Summary Files Commits Branches @commit @diff @stats
path: root / src / tutorials / connect-to-mysql-in-dotnet-ef
diff options
context:
space:
mode:
Commit2098f8d030d52bbbc12a77cbcbdc67b4384b698f (patch)
Author
 Syndamia <kamen@syndamia.com>
2022-09-30 10:47:38 +0300
Committer
 Syndamia <kamen@syndamia.com>
2022-09-30 10:47:38 +0300
Filesebfe06d7220cc8776cf2ce6969eab572217f87fc /src/tutorials/connect-to-mysql-in-dotnet-ef
syndamia.com-2098f8d030d52bbbc12a77cbcbdc67b4384b698f.tar
syndamia.com-2098f8d030d52bbbc12a77cbcbdc67b4384b698f.tar.gz
syndamia.com-2098f8d030d52bbbc12a77cbcbdc67b4384b698f.zip
Parentb28b50b2bc9166fe06d9ee7352af9263e2ceb21e (diff)
[src] Removed manually placed heading anchors in all pages
1 files changed, 0 insertions, 6 deletions
-rw-r--r--src/tutorials/connect-to-mysql-in-dotnet-ef/index.md6
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 dfdb0c0..3a7c7d5 100644
--- a/src/tutorials/connect-to-mysql-in-dotnet-ef/index.md
+++ b/src/tutorials/connect-to-mysql-in-dotnet-ef/index.md
@@ -12,7 +12,6 @@ I have found that connecting a `.NET` application to a `MySql` database (with En
Also, [MySql.Data.EntityFrameworkCore](https://www.nuget.org/packages/MySql.Data.EntityFrameworkCore/) has been **depricated** since *October 2020*. If you need setup instructions with it, read [this](https://gitlab.com/Syndamia/syndamiadotcom/-/blob/0510e29526c6d7681587fff4c98a339e8c69e9b5/src/tutorials/connect-to-mysql-in-csharp-ef/article.md).
## Contents
-<div></div>
1. [NuGet packages](#nuget-packages)
2. [Connection string](#connection-string)
@@ -21,12 +20,10 @@ Also, [MySql.Data.EntityFrameworkCore](https://www.nuget.org/packages/MySql.Data
2. [DBContext child class](#dbcontext-child-class)
## NuGet packages
-[![🔗](/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-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,7 +36,6 @@ 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)
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).
@@ -56,7 +52,6 @@ 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-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 +69,6 @@ The result should look something along the lines of:
<p></p>
### DBContext child class
-[![🔗](/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.