Summary Files Commits Branches @commit @diff @stats
path: root / src / tutorials
diff options
context:
space:
mode:
Commit2b03e07ac231b8ea7b6ce7184b18d11def04df01 (patch)
Author
 Syndamia <kamen.d.mladenov@protonmail.com>
2021-05-25 21:24:21 +0300
Committer
 Syndamia <kamen.d.mladenov@protonmail.com>
2021-05-25 21:24:21 +0300
Files5957211ecd01a10c1ce5430fb76f9b833cfd9e77 /src/tutorials
syndamia.com-2b03e07ac231b8ea7b6ce7184b18d11def04df01.tar
syndamia.com-2b03e07ac231b8ea7b6ce7184b18d11def04df01.tar.gz
syndamia.com-2b03e07ac231b8ea7b6ce7184b18d11def04df01.zip
Parent0555703568964839dc5cff7871f88f36614f1d20 (diff)
Reworked formatting of connect to mysql in csharp tutorial
1 files changed, 12 insertions, 10 deletions
-rw-r--r--src/tutorials/connect-to-mysql-in-csharp-ef/article.md22
diff --git a/src/tutorials/connect-to-mysql-in-csharp-ef/article.md b/src/tutorials/connect-to-mysql-in-csharp-ef/article.md
index 9067faa..187aebc 100644
--- a/src/tutorials/connect-to-mysql-in-csharp-ef/article.md
+++ b/src/tutorials/connect-to-mysql-in-csharp-ef/article.md
@@ -9,17 +9,18 @@ In my experience, connecting a `C#` application to a `MySQL` database with Entit
## Contents
[![🔗](/img/link-tabler.svg)](#Contents)
-1. [Preparation](#Preparation))
+1. [Preparation](#Preparation)
2. [Connecting](#Connecting)
-# Preparation
+## Preparation
+[![🔗](/img/link-tabler.svg)](#Preparation)
-## MySql
+### MySql
[![🔗](/img/link-tabler.svg)](#MySql)
This tutorial doesn't cover it, but you'll need to have properly [installed and configured](https://dev.mysql.com/doc/mysql-installation-excerpt/5.7/en/) `MySQL`.
-## NuGet packages
+### NuGet packages
[![🔗](/img/link-tabler.svg)](#NuGet%20packages)
You'll need to install two NuGet packages: [Microsoft.EntityFrameworkCore](https://www.nuget.org/packages/Microsoft.EntityFrameworkCore) and [MySql.Data.EntityFrameworkCore](https://www.nuget.org/packages/MySql.Data.EntityFrameworkCore/).
@@ -28,9 +29,10 @@ You'll need to install two NuGet packages: [Microsoft.EntityFrameworkCore](https
[MySql.Data.EntityFrameworkCore](https://www.nuget.org/packages/MySql.Data.EntityFrameworkCore/) is what enables Microsoft.EntityFrameworkCore to connect to a `MySQL` database.
-# Connecting
+## Connecting
+[![🔗](/img/link-tabler.svg)](#Connecting)
-## Connection string
+### Connection string
[![🔗](/img/link-tabler.svg)](#Connection%20string)
You can find a truckload of ways to make your connection string from places like [this](https://www.connectionstrings.com/mysql/) but in this case, I've found out that most don't work.
@@ -44,7 +46,7 @@ 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_.
-## ASP.NET Startup
+### ASP.NET Startup
[![🔗](/img/link-tabler.svg)](#ASP.NET%20Startup)
If you are making an `ASP.NET` application, you'll need to put the connection string in the `ConfigureServices` method of the `Startup.cs` file.
@@ -58,15 +60,15 @@ The result should look something like this:
public void ConfigureServices(IServiceCollection services)
{
services.AddControllersWithViews();
- services.AddTransient<UserServices, UserServices>();
+ services.AddTransient<UserServices, UserServices>();
services.AddDbContext<AppDbContext>(opt =>
{
opt.UseMySQL(CONNECTION_STRING);
- });
+ });
}
```
-## DBContext child class
+### DBContext child class
[![🔗](/img/link-tabler.svg)](#DBContext%20child%20class)
If you want to connect a `DBContext` child class to a `MySQL` database, one of the easiest ways to do it, is to override the `OnConfiguring` method.