0

Visual Studio Community Edition을 사용하여 ASP.NET CORE 2.0 MVC를 사용하는 방법을 배웁니다. 이전 MySQL DB에서 일부 데이터를 사용해야하기 때문에 SQL Server 대신 MySQL 데이터베이스를 사용하고 싶습니다. 내가이 문제를 해결 도와주세요 .. 감사합니다 여기 오류 t CS1061 t 'DbContextOptionsBuilder'에 'UseMySql'에 대한 정의가 없습니다.

내 오류입니다 : Startup.cs ( https://pastebin.com/dzx8Hf8Q)

using System; 
using System.Collections.Generic; 
using System.Linq; 
using System.Threading.Tasks; 
using Microsoft.AspNetCore.Builder; 
using Microsoft.AspNetCore.Hosting; 
using Microsoft.Extensions.Configuration; 
using Microsoft.Extensions.DependencyInjection; 
using Microsoft.EntityFrameworkCore; 
using LearnEFCore.Data; 

.... 
// This method gets called by the runtime. Use this method to add services to the container. 
     public void ConfigureServices(IServiceCollection services) 
     { 
      var sqlConnectionString = Configuration.GetConnectionString("DataAccessMySqlProvider"); 
      services.AddDbContext<SchoolContext>(options => options.UseMySql(sqlConnectionString)); 
      services.AddMvc(); 
     } 

에서

에서 : 다음과 같은

Severity Code Description Project File Line Suppression State Error CS1061 'DbContextOptionsBuilder' does not contain a definition for 'UseMySql' and no extension method 'UseMySql' accepting a first argument of type 'DbContextOptionsBuilder' could be found (are you missing a using directive or an assembly reference?) LearnEFCore d:\temp\aspnet\LearnEFCore\LearnEFCore\Startup.cs 29 Active

내 코드 내 appsettings.json

{ 
    "Logging": { 
    "IncludeScopes": false, 
    "LogLevel": { 
     "Default": "Warning" 
    } 
    }, 

    "ConnectionStrings": { 
    "DataAccessMySqlProvider": "server=localhost;port=3306;userid=root;password=root;database=sportstore;" 
    } 
} 
내 모델에서

/데이터

using LearnEFCore.Models; 
using Microsoft.EntityFrameworkCore; 

namespace LearnEFCore.Data 
{ 
    public class SchoolContext : DbContext 
    { 
     public SchoolContext(DbContextOptions<SchoolContext> options) : base(options) 
     { 
     } 

     public DbSet<Course> Courses { get; set; } 
     public DbSet<Enrollment> Enrollments { get; set; } 
     public DbSet<Student> Students { get; set; } 

     protected override void OnModelCreating(ModelBuilder modelBuilder) 
     { 
      modelBuilder.Entity<Course>().ToTable("Course"); 
      modelBuilder.Entity<Enrollment>().ToTable("Enrollment"); 
      modelBuilder.Entity<Student>().ToTable("Student"); 
     } 
    } 
} 

내 csproj Pomelo.EntityFrameworkCore.MySql에 무언가 문제가 해결

<Project Sdk="Microsoft.NET.Sdk.Web"> 

    <PropertyGroup> 
    <TargetFramework>netcoreapp2.0</TargetFramework> 
    </PropertyGroup> 

    <ItemGroup> 
    <PackageReference Include="Microsoft.AspNetCore.All" Version="2.0.0" /> 
    <PackageReference Include="Microsoft.EntityFrameworkCore" Version="2.0.0" /> 
    <PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="2.0.0" /> 
    <PackageReference Include="MySql.Data.EntityFrameworkCore" Version="6.10.4" /> 
    </ItemGroup> 

    <ItemGroup> 
    <DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="2.0.0" /> 
    </ItemGroup> 

</Project> 

답변

관련 문제