I'm currently using this article in an attempt to connect my ASP.NET Core project to my MySql database, and installed the NuGet package "MySqlConnector" as it said. The article then says to add this line to the "ConfigureServices" function in Startup.cs.
services.AddTransient<MySqlConnection>(_ => new MySqlConnection(Configuration["ConnectionStrings:Default"]));
However "MySqlConnection" is underlinde in red, and hovering over it shows the following error:
CS0246: The type or namespace "MySqlConnection" could not be found (are you missing a using directive or an assembly reference?)
Is there something I'm missing? Is there a typo in the article, and I should be installing the MySqlConnection package instead?
The class MySqlconnection
is defined in the namespace MySqlConnector
. You have to add the following using statement at the top of your Startup class:
using MySqlConnector;