Cannot find UseMysql method for DbContextOptions

I am playing with the dotnet kernel in linux and I am trying to configure my DbContext using the mysql server connection string.

my dbcontext looks like this:

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 look like this:

 "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.AspNetCore.Mvc":"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 tried using mysql server in my Startup.cs in the following code

 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 tried to change my directive from

 using Microsoft.EntityFrameworkCore; 

to

 using MySQL.Data.EntityFrameworkCore; 

What makes sense? may be? but then all the links to DbContext and DbSet disappeared, so I suppose the solution is a mixture of varieties.

+5
source share
1 answer

You need

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

Oracle does not follow standard practices when using Dependency Injection, so this is all a bit different. The standard practice is to put extension methods for Injection Dependency into the Microsoft.Extensions.DependencyInjection namespace, which is included in most ASP.NET Core application projects, so the method becomes automatically available when you import the package.

+12
source

Source: https://habr.com/ru/post/1258259/


All Articles