When creating a new project with visual studio, the default database selected is SQL Server. There are many reasons why you may want to use MySQL instead of SQL Server for data storage. The first one that comes to mind is the price. MySQL is free and can be used on more environment than SQL Server - Doesn't really matter for this article since we're showing you how to use Entity framework with MySQL, but worth mentioning mainly if you plan to isolate your application and database servers i.e having them run on different environments.
In this article we will be creating a simple Console C# application to show you how to use Entity Framework with MySQL. Let's get started:
- Type "MySQL" in the search box to download the other package see image below:
<provider invariantName="MySql.Data.MySqlClient" type="MySql.Data.MySqlClient.MySqlProviderServices, MySql.Data.Entity.EF6, Version=220.127.116.11, Culture=neutral, PublicKeyToken=c5687fc88969c44d"></provider>
Build the application to make sure everything works fine so far.
<connectionStrings> <add name="MyConnectionString" connectionString="server=localhost;user id=<MYUSERNAME>;password=<MYPASSWORD>;database=<MYDB>;persistsecurityinfo=True" providerName="MySql.Data.MySqlClient" /> </connectionStrings>
Note: Make sure you replace <MYUSERNAME>, <MYPASSWORD>, <MYDB> with your own information