Setup Entity Framework Core for MySQL in ASP.NET Core 2

Microsoft doesn’t have official package to support MySQL data provider for EF Core (yet). There is an open source package corePomelo.EntityFrameworkCore.MySql maintained by Pomelo Foundation.

We can install this package in .NET Core application using NuGet package manager.

Once package installed, setup connection string in appsettings.json file:

  • Create DbContext and Model classes mapping database tables.
  • Configure MySql service in ConfigureServices of Startup.cs specifying DbContext and connection string. This service shall be queried later for resolving DbContext object via Dependency Injection.
  • Accessing DbContext in controller classes

and that should be it!

Your ASP.NET Core 2 application is setup with EF Core and MySQL database.

Cloud Solution Architect | Author | Full Stack Developer | |

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store