Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UseMySQL extension method not recognized in ASP.NET core

Environment: Ubuntu 16.04, .NET Core 1.10 (1.0.0-preview2-1-003177), Visual Studio Code 1.8.1

I have created an ASP.NET MVC Core application by running the following command:

$ dotnet new -t web

I am able to load the folder in VSC and debug it.

By default, the engine generates code for Sqlite. I am changing it to use MySQL. My changes are based on the information from the following two articles:

http://insidemysql.com/howto-starting-with-mysql-ef-core-provider-and-connectornet-7-0-4/ https://damienbod.com/2016/08/26/asp-net-core-1-0-with-mysql-and-entity-framework-core/

First, I added the following lines into dependencies section of project.json.

"MySql.Data.Core" :"7.0.4-ir-191",
"MySql.Data.EntityFrameworkCore": "7.0.6-IR31"

After running dotnet restore, the required DLLs were downloaded.

The next step was to modify Startup.cs and modify

 services.AddDbContext<ApplicationDbContext>(options =>
    options.UseSqlite(Configuration.GetConnectionString("DefaultConnection")));

to

 services.AddDbContext<ApplicationDbContext>(options =>
    options.UseMySQL(Configuration.GetConnectionString("DefaultConnection")));

Essentially, I am replacing UseSqlite by UseMySQL.

However, extension method UseMySQL or UseMySQL do not seem to be available on DbContextOptionsBuilder.

Wondering if I missed some step somewhere. Regards.

like image 761
Peter Avatar asked Jan 22 '17 23:01

Peter


2 Answers

Add the using MySql.Data.EntityFrameworkCore.Extensions; statement.

like image 67
Shaun Luttin Avatar answered Oct 12 '22 14:10

Shaun Luttin


I also had the same issue even though was installing the Pomelo.EntityFrameworkCore.MySql, just installed the package through the terminal:

dotnet add package Pomelo.EntityFrameworkCore.MySql

it worked!

like image 39
Farid Huseynov Avatar answered Oct 12 '22 14:10

Farid Huseynov