From 46f51427c86ad8cb0f695adcd6c93a7a29a8f496 Mon Sep 17 00:00:00 2001 From: Syndamia Date: Thu, 17 Feb 2022 17:12:31 +0200 Subject: Added "syntax highlighting" styling and implemented it in the connect to mysql article --- .../connect-to-mysql-in-dotnet-ef/article.md | 31 +++++++++------------- 1 file changed, 13 insertions(+), 18 deletions(-) (limited to 'src/tutorials') diff --git a/src/tutorials/connect-to-mysql-in-dotnet-ef/article.md b/src/tutorials/connect-to-mysql-in-dotnet-ef/article.md index 775bab1..4b3a5da 100644 --- a/src/tutorials/connect-to-mysql-in-dotnet-ef/article.md +++ b/src/tutorials/connect-to-mysql-in-dotnet-ef/article.md @@ -50,9 +50,8 @@ The method requires at least two arguments: connection string and `MySql` server For the server version argument, create a new object of type `MySqlServerVersion` and give it's constructor a new object of type `Version`, to which you give the version numbers. The result should look something like this: -``` -.UseMySql(CONNECTION_STRING, new MySqlServerVersion(new System.Version(8, 0, 21))) -``` +
.UseMySql(CONNECTION_STRING, new MySqlServerVersion(new System.Version(8, 0, 21)))
+
Where `CONNECTION_STRING` is a (constant) variable that contains your connection string, and 8, 0, 21 are the version numbers. @@ -63,17 +62,15 @@ For `ASP.NET` applications, the connection must be put inside the `ConfigureServ The result should look something along the lines of: -``` -// This method gets called by the runtime. Use this method to add services to the container. -public void ConfigureServices(IServiceCollection services) +
// This method gets called by the runtime. Use this method to add services to the container.
+public void ConfigureServices(IServiceCollection services)
 {   
-	...                 
-	services.AddDbContext(opt =>
-	{
-		opt.UseMySql(...);
-	}); 
-}
-```
+    ...
+    services.AddDbContext<AppDbContext>(opt =>
+    {
+        opt.UseMySql(...);
+    });
+}

### DBContext child class @@ -81,10 +78,8 @@ public void ConfigureServices(IServiceCollection services) 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. -``` -protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) +
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
 {
-	optionsBuilder.UseMySql(...);
-}
-```
+    optionsBuilder.UseMySql(...);
+}

-- cgit v1.3.1-23-gd82d