diff options
Added "syntax highlighting" styling and implemented it in the connect to mysql article
1 files changed, 13 insertions, 18 deletions
| -rw-r--r-- | src/tutorials/connect-to-mysql-in-dotnet-ef/article.md | 31 |
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))) -``` +<pre><code>.<span class="fnc">UseMySql</span>(CONNECTION_STRING, <span class="kwd">new</span> <span class="cls">MySqlServerVersion</span>(<span class="kwd">new</span> <span class="kwD">System</span>.<span class="cls">Version</span>(<span class="cst">8</span>, <span class="cst">0</span>, <span class="cst">21</span>))) +</code></pre> 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) +<pre><code><span class="com">// This method gets called by the runtime. Use this method to add services to the container.</span> +<span class="kwd">public</span> <span class="typ">void</span> <span class="fnc">ConfigureServices</span>(<span class="cls">IServiceCollection</span> services) { - ... - services.AddDbContext<AppDbContext>(opt => - { - opt.UseMySql(...); - }); -} -``` + <span class="com">...</span> + services.<span class="fnc">AddDbContext</span><<span class="cls">AppDbContext</span>>(opt => + { + opt.<span class="fnc">UseMySql</span>(<span class="com">...</span>); + }); +}</code></pre> <p></p> ### 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) +<pre><code><span class="kwd">protected</span> <span class="kwd">override</span> <span class="typ">void</span> <span class="fnc">OnConfiguring</span>(<span class="cls">DbContextOptionsBuilder</span> optionsBuilder) { - optionsBuilder.UseMySql(...); -} -``` + optionsBuilder.<span class="fnc">UseMySql</span>(<span class="com">...</span>); +}</code></pre> <p></p> |