Cannot find the UseMysql method on DbContextOptions c# entity-framework mysql


I'm experimenting with the linux version of the dotnet core and attempting to set up my DbContext to connect to a MySQL server.

My DbContext is as follows:

using Microsoft.EntityFrameworkCore;
using Models.Entities;

namespace Models {
    public class SomeContext : DbContext
        //alot of dbSets...
        public DbSet<SomeEntity> SomeDbSet { get; set; }

        public EsportshubContext(DbContextOptions<SomeContext> options) : base(options) {


        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) 
            optionsBuilder.UseMysql //Cannot find this method

        protected override void OnModelCreating(ModelBuilder modelBuilder) 
            //using modelBuilder to map some relationships

My dependencies appear as follows:

"dependencies": {
    "Microsoft.NETCore.App": {
      "version": "1.0.0",
      "type": "platform"
    "Microsoft.AspNetCore.Diagnostics": "1.0.0",
    "Microsoft.AspNetCore.Server.IISIntegration": "1.0.0",
    "Microsoft.AspNetCore.Server.Kestrel": "1.0.1",
    "Microsoft.Extensions.Logging.Console": "1.0.0",
    "Microsoft.Extensions.Configuration.EnvironmentVariables": "1.0.0",
    "Microsoft.Extensions.Configuration.FileExtensions": "1.0.0",
    "Microsoft.Extensions.Configuration.Json": "1.0.0",
    "Microsoft.Extensions.Configuration.CommandLine": "1.0.0",
    "Microsoft.EntityFrameworkCore": "1.0.1",
    "MySql.Data.Core": "7.0.4-ir-191",
    "MySql.Data.EntityFrameworkCore": "7.0.4-ir-191"

I also attempted to utilise the MySQL server in the following line of code in my Startup.cs file.

public class Startup

        public void ConfigureServices(IServiceCollection services)
            var connection = @"Server=(localdb)\mssqllocaldb;Database=EFGetStarted.AspNetCore.NewDb;Trusted_Connection=True;";
            services.AddDbContext<EsportshubContext>(options => options.UseMysql); //Cannot find UseMysql*

I made an effort to switch my order from

using Microsoft.EntityFrameworkCore;


using MySQL.Data.EntityFrameworkCore;

which is logical? maybe? However, all references to DbContext and DbSet are lost, therefore I think a combination of solutions is needed.

10/15/2016 1:58:54 PM

Accepted Answer

You must

using Microsoft.EntityFrameworkCore;
using MySQL.Data.EntityFrameworkCore.Extensions;

Oracle's use of Dependency Injection deviates from best standards, therefore everything is a little different. The accepted procedure is to include the extension techniques for dependency injectionMicrosoft.Extensions.DependencyInjection The function is made instantly accessible when a package is imported thanks to namespace, which is included in most ASP.NET Core app projects.

10/15/2016 2:32:39 PM

Popular Answer

If you do not useMySQL.Data.EntityFrameworkCore package. You could be using thePomelo.EntityFrameworkCore.MySql MySql package for EntityFramework Core.

If so, include these words:

using Microsoft.EntityFrameworkCore;
using Pomelo.EntityFrameworkCore;

Related Questions


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