ASP.Net Core, Entity Framework and MySQL Gives a Create exception? Any ideas why?

0

I have a working ASP.Net Core application with SQL Server and Entity Framework. I use DI to inject the database context. The solution has a web project and a data project. I am looking to move to MySql and have made some small changes to the code.

Running the application gives me the error

System.TypeLoadException
  HResult=0x80131522
  Message=Method 'Create' in type 'MySql.Data.EntityFrameworkCore.Query.Internal.MySQLSqlTranslatingExpressionVisitorFactory' from assembly 'MySql.Data.EntityFrameworkCore, Version=8.0.22.0, Culture=neutral, PublicKeyToken=c5687fc88969c44d' does not have an implementation.
  Source=MySql.Data.EntityFrameworkCore

These are my changes (apart from connection string which I changed and know it works):

In Startup.cs in the web project

public void ConfigureServices(IServiceCollection services)
{
   ...
   services.AddDbContext<DatabaseModel>(options => options.UseMySQL(Configuration.GetConnectionString("Dev")));
   ...
}

Installed using Nuget into the data project

MySQL.Data.EntityFrameworkCore v8.0.22
(this installs Microsoft.EntityFrameworkCore.Relational and MySql.Data)

I cannot reference using MySQL.Data.EntityFrameworkCore.Extensions; as I get an error (red line under Extensions) so something hasn't been referenced but it compiles ok.

In DatabaseModel.cs in the data project

using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.EntityFrameworkCore;         
using MySQL.Data.EntityFrameworkCore;        <========= this has been added by me
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using Microsoft.Extensions.Configuration;

public partial class DatabaseModel : DbContext  <========= no changes to this class
{
   ....
}

Any ideas? I have used MySQL in ASP.Net but not Core so I am thinking that I have a missing package but not sure.

c#
mysql
asp.net-core
entity-framework-core
asked on Stack Overflow Dec 5, 2020 by user3807918 • edited Dec 5, 2020 by user3807918

1 Answer

1

I have found that the solution is downgrading Microsoft.EntityFrameworkCore to version 3.1.10.

I had it at V5.0.0

answered on Stack Overflow Dec 5, 2020 by user3807918

User contributions licensed under CC BY-SA 3.0