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

Balram Chavan
Mar 3, 2018 · 1 min read

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.

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade

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