diff options
4 files changed, 0 insertions, 165 deletions
| -rw-r--r-- | website/tutorials/connect-to-mysql-in-csharp-ef/connecting.html | 81 | ||||
| -rw-r--r-- | website/tutorials/connect-to-mysql-in-csharp-ef/img/connections.png | bin | 10067 -> 0 bytes | |||
| -rw-r--r-- | website/tutorials/connect-to-mysql-in-csharp-ef/introduction.html | 41 | ||||
| -rw-r--r-- | website/tutorials/connect-to-mysql-in-csharp-ef/preparation.html | 43 |
diff --git a/website/tutorials/connect-to-mysql-in-csharp-ef/connecting.html b/website/tutorials/connect-to-mysql-in-csharp-ef/connecting.html deleted file mode 100644 index c3fcdff..0000000 --- a/website/tutorials/connect-to-mysql-in-csharp-ef/connecting.html +++ /dev/null @@ -1,81 +0,0 @@ -<!DOCTYPE html> -<html lang="en-us"> -<html> - <head id="mySqlConnectEntityFrameworkCSharp"> - <meta charset="UTF-8"> - <meta name="description" content="Code you need to write to connect to MySql in C# and Entitiy Framework"> - <meta name="keywords" content="programming, C#, tutorial, mysql, entity, framework, database, asp.net, dbcontext, connectionstring, connection"> - <meta name="author" content="Kamen Mladenov"> - <meta name="robots" content="index, follow"> - <meta name="viewport" content="width=device-width, initial-scale=1.0"> - <link rel="icon" href="../../img/favicon.png" type="image/png"/> - <link rel="shortcut icon" href="../../img/favicon.png" type="image/png"/> - <title>Connect to MySql in C# and Entitiy Framework - Connecting</title> - <link rel="stylesheet" href="../../css/styles.css"> - <link rel="stylesheet" href="../../css/styles-multiple-page-articles.css"> - </head> - - <body id="Connecting"> - <div class="header"> - <script type="text/javascript" src="../../js/header.js"></script> - </div> - - <div class="page"> - <h2>Connection string</h2> - <p> - You can find many ways to impliment your connection string from <a href="https://www.connectionstrings.com/mysql/" class="hyperlink">here</a>. - From experience, this one works the best: <br> - <p class="code"> - "server=localhost; port=YOUR-PORT; user id=YOUR-USER-ID; password=YOUR-PASSWORD; database=NAME-OF-DATABASE; SslMode=none" - </p> - If you don't know your port or user id, just look at the connection you use to connect to the database. - </p> - <p class="tutorial-p"> - <img src="./img/connections.png" alt="MyServer root 127.0.0.1:3306" class="tutorial-img" width="262" height="152"> - <span class="tutorial-text"> - In this example, the user id is <i>root</i> and the port is <i>3306</i>. - </span> - </p> - <br> - <h2>ASP.NET Startup</h2> - <p> - If you are making an ASP.NET application, you will need to alter your Startup.cs file. - </p> - <p> - Your ConfigureServices method should currenly look something like this: - <p class="code"> -  // This method gets called by the runtime. Use this method to add services to the container. <br> -  public void ConfigureServices(IServiceCollection services) <br> -  { <br> -   services.AddControllersWithViews(); <br> -   services.AddTransient<UserServices, UserServices>(); <br> -   services.AddDbContext<AppDbContext>(opt => <br> -   { <br> -    opt.UseSQL(CONNECTION_STRING); <br> -   }); <br> -  } - </p> - You need to change <span class="code">.UseSQL</span> to <span class="code">.UseMySQL</span> (refer to <a href="./preparations" class="hyperlink">preparations</a> if you haven't already). - </p> - <br> - <h2>DBContext child class</h2> - <p> - If you want to connect a DBContext child class to a MySQL databse, the best way is to override the <span class="code">OnConfiguring</span> method. In the override, in <span class="code">optionsBuilder</span>, call the <span class="code">.UseMySQL</span> method (refer to <a href="./preparations" class="hyperlink">preparations</a> if you haven't already). - </p> - <p> - Example: - <p class="code"> -  protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) <br> -  { <br> -   optionsBuilder.UseMySQL(DataBaseContexts.ConnectionStringMySQL); <br> -  } <br> - </p> - </p> - </div> - - <br> - - <footer id="child-child-dir" class="footer"></footer> - </body> - <script type="text/javascript" src="../../js/footer.js"></script> -</html> diff --git a/website/tutorials/connect-to-mysql-in-csharp-ef/img/connections.png b/website/tutorials/connect-to-mysql-in-csharp-ef/img/connections.png Binary files differdeleted file mode 100644 index aa7b408..0000000 --- a/website/tutorials/connect-to-mysql-in-csharp-ef/img/connections.png +++ /dev/null diff --git a/website/tutorials/connect-to-mysql-in-csharp-ef/introduction.html b/website/tutorials/connect-to-mysql-in-csharp-ef/introduction.html deleted file mode 100644 index d25999e..0000000 --- a/website/tutorials/connect-to-mysql-in-csharp-ef/introduction.html +++ /dev/null @@ -1,41 +0,0 @@ -<!DOCTYPE html> -<html lang="en-us"> -<html> - <head id="mySqlConnectEntityFrameworkCSharp"> - <meta charset="UTF-8"> - <meta name="description" content="Connecting to MySql through C# can be quite tricky. For that reason, I am making this tutorial."> - <meta name="keywords" content="programming, C#, tutorial, mysql, entity, framework, database, asp.net, dbcontext, connectionstring, connection"> - <meta name="author" content="Kamen Mladenov"> - <meta name="robots" content="index, follow"> - <meta name="viewport" content="width=device-width, initial-scale=1.0"> - <link rel="icon" href="../../img/favicon.png" type="image/png"/> - <link rel="shortcut icon" href="../../img/favicon.png" type="image/png"/> - <title>Connect to MySql in C# and Entitiy Framework - Introduction</title> - <link rel="stylesheet" href="../../css/styles.css"> - <link rel="stylesheet" href="../../css/styles-multiple-page-articles.css"> - </head> - - <body id="Introduction"> - <div class="header"> - <script type="text/javascript" src="../../js/header.js"></script> - </div> - - <div class="page"> - <p> - 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. - </p> - <p> - First are preparations in which I will talk about what you need to have for this to work. - </p> - <p> - Second is the actual connecting. This covers changes in code and the all mighty connection string. - </p> - </div> - - <br> - - <footer id="child-child-dir" class="footer"> - <script type="text/javascript" src="../../js/footer.js"></script> - </footer> - </body> -</html> diff --git a/website/tutorials/connect-to-mysql-in-csharp-ef/preparation.html b/website/tutorials/connect-to-mysql-in-csharp-ef/preparation.html deleted file mode 100644 index cd1930b..0000000 --- a/website/tutorials/connect-to-mysql-in-csharp-ef/preparation.html +++ /dev/null @@ -1,43 +0,0 @@ -<!DOCTYPE html> -<html lang="en-us"> -<html> - <head id="mySqlConnectEntityFrameworkCSharp"> - <meta charset="UTF-8"> - <meta name="description" content="Things you need to do as preparations for connecting to MySql in C# and Entitiy Framework"> - <meta name="keywords" content="programming, C#, tutorial, mysql, entity, framework, database, asp.net, dbcontext, connectionstring, connection"> - <meta name="author" content="Kamen Mladenov"> - <meta name="robots" content="index, follow"> - <meta name="viewport" content="width=device-width, initial-scale=1.0"> - <link rel="icon" href="../../img/favicon.png" type="image/png"/> - <link rel="shortcut icon" href="../../img/favicon.png" type="image/png"/> - <title>Connect to MySql in C# and Entitiy Framework - Preparation</title> - <link rel="stylesheet" href="../../css/styles.css"> - <link rel="stylesheet" href="../../css/styles-multiple-page-articles.css"> - </head> - - <body id="Preparation"> - <div class="header"> - <script type="text/javascript" src="../../js/header.js"></script> - </div> - - <div class="page"> - <h2>MySql</h2> - <p> - First of all, you need to insall MySql. You can do that from <a href="https://dev.mysql.com/downloads/installer/" class="hyperlink" target="_blank">here</a>. This is the installer. Skip this step, if you have already done it. - </p> - <h2>NuGet packages</h2> - <p> - For an Entity Framework, <a href="https://www.nuget.org/packages/Microsoft.EntityFrameworkCore" class="hyperlink" target="_blank">Microsoft.EntitiyFrameworkCore</a> is the goto packet in this tutorial. - </p> - <p> - Although <a href="https://www.nuget.org/packages/Microsoft.EntityFrameworkCore" class="hyperlink" target="_blank">Microsoft.EntitiyFrameworkCore</a> does offer connectivity with MS SQL server, <b>it doesn't offer anything for MySql</b>. <br> - That's why we also need to install another package: <a href="https://www.nuget.org/packages/MySql.Data.EntityFrameworkCore/" class="hyperlink" target="_blank">MySql.Data.EntitiyFrameworkCore</a>. - </p> - </div> - - <br> - - <footer id="child-child-dir" class="footer"></footer> - </body> - <script type="text/javascript" src="../../js/footer.js"></script> -</html> |