Reputation: 15955
Upgrading an ASP.NET Core Web Application to .NET Core 2.0, I'm having difficulty with MySQL extension method not found after upgrading to MySQL 8.0.8-dmr release.
MySQL Data Entity Framework Core was upgraded to 8.0.8-dmr
$ dotnet add package MySql.Data.EntityFrameworkCore --version 8.0.8-dmr
In my Startup.cs
, I have:
using MySQL.Data.EntityFrameworkCore;
using MySQL.Data.EntityFrameworkCore.Extensions;
But in the MySQL 8.0.8-dmr release, the Extensions
namespace is not found.
error CS0234: The type or namespace name 'Extensions' does not exist in the namespace 'MySql.Data.EntityFrameworkCore' (are you missing an assembly reference?)
This is required to use MySQL, as in ConfigureServices()
:
public void ConfigureServices(IServiceCollection services)
{
services.AddDbContext<ApplicationDbContext>(options =>
options.UseMySQL(Configuration.GetConnectionString("DefaultConnection")));
Without the extension method, this results in:
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
Is there a different methodology for using MySQL in ASP.NET Core 2 Web Apps?
Upvotes: 2
Views: 2017
Reputation: 13
Maybe can helps
I my testing I build a 5.5.56-MariaDB Works with visualStudio 2017 The project is asp .net core 2 I install Microsoft.EntityFrameworkCore.Tools v2.0.1 Pomelo.EntityFrameworkCore.MySql v2.0.0.1 and by default VS install Microsoft.AspNetCore.All v2.0.3 Microsoft.NETCore.App v2.0.0 And don't forget when you type your command specify the entity framework you want use... EntityFrameworkCore\update-database
In my DbContext:
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
=> optionsBuilder
.UseMySql(@"Server=hostIp;database=dbName;uid=root;pwd=123456;");
Works well for me
More info on Pomelo @ https://github.com/PomeloFoundation/Pomelo.EntityFrameworkCore.MySql/blob/master/README.md#getting-started
Upvotes: 0
Reputation: 64150
As pointed in the comments, try changing the casing, i.e. UseMysql
. Also check for nuget package restore warnings.
Upvotes: 1