I am using Visual Studio 2019 community edition. I want to connect to MySQL using Entity Framework core. I do not want to use Entity Framework 6.
I am running into following issues:


Step by Step - Database First
First install these packages
So on Powershell go to project folder [right click on project and select open in terminal (visual studio)]

Now, you can run this command

dotnet ef dbcontext scaffold "Servel=localhost;Database=tempSQLonNetCore;user=root;password=;" "Pomelo.EntityFrameworkCore.MySql"
Now you must inject DbContext, Described in the Codefirst section
Step by Step - Code First
First install these packages
Add connection string look like in appsetting.json
"ConnectionStrings" : {
"DefaultConnection" : "Servel=localhost;Database=tempSQLonNetCore;user=root;password=;"
}
**Now, Create your DB context **
public class ApplicationDbContext : DbContext
{
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options) : base(options)
{
}
// Your Entities
}
finally configure the app for connecting
var connectionString = builder.Configuration.GetConnectionString("DefaultConnection");
builder.Services.AddDbContext<ApplicationDbContext>(options => {
options.UseMySql(connectionString, ServerVersion.AutoDetect(connectionString));
});
Now you can use Migration if you need to create or update your database Migration
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