From 2b03e07ac231b8ea7b6ce7184b18d11def04df01 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Tue, 25 May 2021 21:24:21 +0300 Subject: Reworked formatting of connect to mysql in csharp tutorial --- .../connect-to-mysql-in-csharp-ef/article.md | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) (limited to 'src/tutorials') 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(); + services.AddTransient(); services.AddDbContext(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. -- cgit v1.3.1-23-gd82d