Pomelo.EntityFrameworkCore.Mysql error DBContextOptionsBuilder does not contain a definition for UseMyQL

asp.net-core entity-framework-core visual-studio-2017

Question

I just installed Visual Studio 17 and I want to use mysql as my database to develop a WebAPI.

My csproj:

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

  <PropertyGroup>
    <TargetFramework>netcoreapp1.1</TargetFramework>
  </PropertyGroup>

  <ItemGroup>
    <Folder Include="wwwroot\" />
  </ItemGroup>
  <ItemGroup>
    <PackageReference Include="Microsoft.ApplicationInsights.AspNetCore" Version="2.0.0" />
    <PackageReference Include="Microsoft.AspNetCore" Version="1.1.1" />
    <PackageReference Include="Microsoft.AspNetCore.Mvc" Version="1.1.2" />
    <PackageReference Include="Microsoft.EntityFrameworkCore" Version="1.1.1" />
    <PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="1.1.1" />
    <PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="1.1.1" />
  </ItemGroup>
  <ItemGroup>
    <DotNetCliToolReference Include="Microsoft.VisualStudio.Web.CodeGeneration.Tools" Version="1.0.0" />
  </ItemGroup>

</Project>

From NuGet package manager I installed Pomelo.EntityFrameworkCore.Mysql.

My aspsettings.json:

{
  "ConnectionStrings": {
    "MysqlConnection": "server=localhost;userid=root;pwd=root;port=3306;database=aspnet;sslmode=none;"
  },
  "Logging": {
    "IncludeScopes": false,
    "LogLevel": {
      "Default": "Warning"
    }
  }
}

In my strtup.cs inside ConfigureServices() I have:

services.AddDbContext<WebAPIDataContext>(options =>
            {
                options.UseMySQL(Configuration.GetConnectionString("MysqlConnection")); }
            );
 services.AddMvc();
 services.AddScoped<IProfileRepository, ProfileRepository>();

However, it is giving me DBContextOptionsBuilder does not contain a definition for UseMyQL error. Why is it that?

1
0
5/2/2017 3:14:47 PM

Popular Answer

I changed it to:

// Add framework services.
            services.AddDbContext<WebAPIDataContext>(options =>
            {
                options.UseMySql(Configuration.GetConnectionString("MysqlConnection"));
            });
1
5/2/2017 4:53:17 PM


Related Questions





Related

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