Summary Files Commits Branches @commit @diff @stats
path: root / src / tutorials
diff options
context:
space:
mode:
Commit64fbbd514733e42dd047bf65c511563a84ebd629 (patch)
Author
 Syndamia <kamen.d.mladenov@protonmail.com>
2020-07-21 23:17:07 +0300
Committer
 Syndamia <kamen.d.mladenov@protonmail.com>
2020-07-21 23:17:07 +0300
Filesfb472631d0b32a667b179f87b1e6c7692f09c0b7 /src/tutorials
syndamia.com-64fbbd514733e42dd047bf65c511563a84ebd629.tar
syndamia.com-64fbbd514733e42dd047bf65c511563a84ebd629.tar.gz
syndamia.com-64fbbd514733e42dd047bf65c511563a84ebd629.zip
Parent2d6a1a2b4a5bedfb5c669a48b64d84ed6265853e (diff)
Fully reworked website design. Remade pages in markdown. Configured files to work with ssg5.
diff --git a/src/tutorials/connect-to-mysql-in-csharp-ef/connecting.md b/src/tutorials/connect-to-mysql-in-csharp-ef/connecting.md
new file mode 100644
index 0000000..a91163c
--- /dev/null
+++ b/src/tutorials/connect-to-mysql-in-csharp-ef/connecting.md
@@ -0,0 +1,53 @@
+# Connect to MySql in C# and Entity Framework - Connecting
+
+**Article Created: 21 May 2020** || **Last Edited: 21 July 2020**
+
+[\< Preparations](./preparation.html)
+
+---
+
+## Connection string
+
+You can find many ways to impliment your connection string from [here](https://www.connectionstrings.com/mysql/).
+From experience, this one works the best:
+
+```
+"server=localhost; port=YOUR-PORT; user id=YOUR-USER-ID; password=YOUR-PASSWORD; database=NAME-OF-DATABASE; SslMode=none"
+```
+
+If you don't know your port or user id, just look at the connection you use to connect to the database.
+
+![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
+
+If you are making an ASP.NET application, you will need to alter your Startup.cs file.
+Your ConfigureServices method should currenly look something like this:
+
+```
+// This method gets called by the runtime. Use this method to add services to the container.
+public void ConfigureServices(IServiceCollection services)
+{
+ services.AddControllersWithViews();
+ services.AddTransient<UserServices, UserServices>();
+ services.AddDbContext<AppDbContext>(opt =>
+ {
+ opt.UseSQL(CONNECTION_STRING);
+ });
+}
+```
+
+You need to change `.UseSQL` to `.UseMySQL` (refer to [preparations](./preparation.html) if you haven't already).
+
+## DBContext child class
+
+If you want to connect a DBContext child class to a MySQL databse, the best way is to override the `OnConfiguring` method. In the override, in `optionsBuilder`, call the `.UseMySQL` method (refer to [preparations](./preparation.html) if you haven't already).
+Example:
+
+```
+protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
+{
+ optionsBuilder.UseMySQL(DataBaseContexts.ConnectionStringMySQL);
+}
+```
+
diff --git a/src/tutorials/connect-to-mysql-in-csharp-ef/img/connections.png b/src/tutorials/connect-to-mysql-in-csharp-ef/img/connections.png
new file mode 100644
index 0000000..aa7b408
--- /dev/null
+++ b/src/tutorials/connect-to-mysql-in-csharp-ef/img/connections.png
Binary files differ
diff --git a/src/tutorials/connect-to-mysql-in-csharp-ef/introduction.md b/src/tutorials/connect-to-mysql-in-csharp-ef/introduction.md
new file mode 100644
index 0000000..2a2bd62
--- /dev/null
+++ b/src/tutorials/connect-to-mysql-in-csharp-ef/introduction.md
@@ -0,0 +1,19 @@
+# Connect to MySql in C# and Entity Framework - Introduction
+
+**Article Created: 21 May 2020** || **Last Edited: 21 July 2020**
+
+[Preparation >](./preparation.html)
+
+---
+
+Connecting to `MySql` through `C#` can be quite tricky. I and many others have wasted too much time trying to figure this out. For that reason, I am making this tutorial.
+
+First are preparations in which I will talk about what you need to have for this to work.
+
+Second is the actual connecting. This covers changes in code and the all mighty connection string.
+
+## Contents
+
+1. [Introduction](./introduction.html)
+2. [Preparation](./preparation.html)
+3. [Connecting](./connecting.html)
diff --git a/src/tutorials/connect-to-mysql-in-csharp-ef/preparation.md b/src/tutorials/connect-to-mysql-in-csharp-ef/preparation.md
new file mode 100644
index 0000000..d7eed0d
--- /dev/null
+++ b/src/tutorials/connect-to-mysql-in-csharp-ef/preparation.md
@@ -0,0 +1,20 @@
+# Connect to MySql in C# and Entity Framework - Preparation
+
+**Article Created: 21 May 2020** || **Last Edited: 21 July 2020**
+
+[\< Introduction](./introduction.html) || [Connecting >](./connecting.html)
+
+---
+
+## MySql
+
+First of all, you need to insall MySql. You can do that from [here](https://dev.mysql.com/downloads/installer/). This is the installer. Skip this step, if you have already done it.
+
+## NuGet packages
+
+For an Entity Framework, [Microsoft.EntitiyFrameworkCore](https://www.nuget.org/packages/Microsoft.EntityFrameworkCore) is the goto packet in this tutorial.
+
+Although [Microsoft.EntitiyFrameworkCore](https://www.nuget.org/packages/Microsoft.EntityFrameworkCore) does offer connectivity with MS SQL server, **it doesn't offer the specific things for MySql**.
+
+That's why we need to also install another package: [MySql.Data.EntitiyFrameworkCore](https://www.nuget.org/packages/MySql.Data.EntityFrameworkCore/).
+