Ошибка CS1061 «DbContextOptionsBuilder» не содержит определения для «UseMySql».

Я просто учусь использовать ASP.NET CORE 2.0 MVC с помощью Visual Studio Community Edition. Я хочу использовать базу данных MySQL вместо использования SQL Server, потому что мне нужно использовать некоторые данные внутри старой базы данных MySQL. Пожалуйста, помогите мне решить эту проблему .. спасибо

Вот моя ошибка:

Код серьезности Описание Ошибка состояния подавления строки файла проекта CS1061 «DbContextOptionsBuilder» не содержит определения для «UseMySql», и не удалось найти метод расширения «UseMySql», принимающий первый аргумент типа «DbContextOptionsBuilder» (вы пропустили директиву using или ссылка на сборку?) LearnEFCore d:\temp\aspnet\LearnEFCore\LearnEFCore\Startup.cs 29 Active

Мой код выглядит следующим образом:

В Startup.cs

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();
        }

В моем 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

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

person nightingale2k1    schedule 30.10.2017    source источник


Ответы (1)


переход на Pomelo.EntityFrameworkCore.MySql решил проблему...

person nightingale2k1    schedule 30.10.2017