asp net core mysql connection with entity framework

c# entity-framework-6 mysql

Question

I want to add entity framework to my API project, my database is mysql

how can I do it

.net core version:2.1.2

1
-3
10/10/2019 1:17:06 PM

Accepted Answer

You need to use MySql.Data.EntityFrameworkCore.

1) Install the MySql.Data.EntityFrameworkCore NuGet package.

2) In the class that derives from the DbContext class, override the OnConfiguring method to set the MySQL data provider with UseMySQL. The following example shows how to set the provider using a generic connection string in C#.

protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{   
    optionsBuilder.UseMySQL("server=localhost;database=library;user=user;password=password");
}

Check the available MySQL documentation for more details.

0
10/10/2019 1:32:33 PM


Related Questions





Related

Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow
Licensed under: CC-BY-SA with attribution
Not affiliated with Stack Overflow