WebAPI EF With MySql Database
WebAPI EF With MySql Database
MySql.Data.Entity (latest version is 6.10.X) and MySql.Data (latest version is 8.0.X). Those
version numbers should match. You should use the MySql.Data.EntityFramework package
with MySql.Data version 8.0 and after, and the MySql.Data.Entity package with versions
6.10 and before.
Web => Asp.Net Web Application => Select MVC Project Template
1) Enter Command => Install MySql.Data => Press Enter ( You have to connected to
internet)
After installing packages go to web config file and add connection string with name
DefaultConnection, be sure u have installed mysql server on your local computer or set
connection string for remote server.
[DbConfigurationType(typeof(MySqlEFConfiguration))]
public class ApplicationDbContext : DbContext
{
[Required]
[StringLength(50)]
public string Name { get; set; }
}
If you want to check open the mysql workbench and check there is a database created with
name testDb and it has products table also.
GlobalConfiguration.Configure(WebApiConfig.Register);
Build your application and test your api going following url:
http:localhost:port/api/products (replace port no with your application port)
you can also test your api using postman or any other restclient
Thank you