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.
Add the using MySql.Data.EntityFrameworkCore.Extensions;
statement.
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!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With