diff options
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.md | 22 |
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 [](#Contents) -1. [Preparation](#Preparation)) +1. [Preparation](#Preparation) 2. [Connecting](#Connecting) -# Preparation +## Preparation +[](#Preparation) -## MySql +### MySql [](#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 [](#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 +[](#Connecting) -## Connection string +### Connection string [](#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  In this example, the user id is _root_ and the port is _3306_. -## ASP.NET Startup +### ASP.NET Startup [](#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 [](#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. |