2016-10-15 13 views
5

Linux üzerinde dotnet core ile oynamaktayım ve DbContext'i bir mysql Server'a bir bağlantı dizesi ile yapılandırmaya çalışıyorum.DbContextOptions üzerinde UseMysql yöntemi bulunamıyor

benim DBContext şöyle görünür:

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 
     } 
    } 
} 

Benim bağımlılıkları şöyle görünür:

"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" 
    }, 

şunlarla kodda benim Startup.cs mysql sunucusunu kullanmaya çalıştı

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* 
     } 

Yönergemeyi

değiştirmeye çalıştım

mantıklı
using MySQL.Data.EntityFrameworkCore; 

-e doğru 210

using Microsoft.EntityFrameworkCore; 

? olabilir? ama sonra DbContext ve DbSet'e yapılan tüm referanslar gitti, bu yüzden çözümün bir çeşit karışımı olduğunu düşünüyorum.

cevap

11

Sen

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

Oracle Bağımlılık Injection kullanırken standart uygulamalara uygun, yani onun tüm biraz farklı değildir gerekir. Standart uygulama, bir ASP.NET Core uygulama projelerinde yer alan Microsoft.Extensions.DependencyInjection ad alanı içine Depedency Injection için uzantı yöntemleri koymaktır, böylece bir paket alındığında yöntem otomatik olarak kullanılabilir hale gelir.

+0

MySQL.Data.EntityFrameworkCore.Extensions kullandığınız tam "using deyimi" olduğunu nasıl anladın? – DenLilleMand

+1

Hey, Oracle'ın kodlarını Microsoft'un altına koymanın bir yolu yoktur. * 'Namespace :) –

+0

@IvanStoev: Mysql sağlayıcısını enjekte etmek/kaydetmek için kullanılan uzantı yöntemleri, yani Microsoft'a özgü herhangi bir çerçeveye özgü kod değil. Extension.DependencyInjection', bunun için çok uygundur, çünkü kod, (ASP) .NET Core – Tseng

İlgili konular