【发布时间】:2021-03-17 13:06:51
【问题描述】:
我有一个使用 SQL Server 和实体框架的 ASP.Net Core 应用程序。我使用 DI 注入数据库上下文。该解决方案有一个 Web 项目和一个数据项目。我希望迁移到 MySql,并对代码进行了一些小改动。
运行应用程序给了我错误
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
这些是我的更改(除了我更改并知道它有效的连接字符串):
在 Web 项目的 Startup.cs 中
public void ConfigureServices(IServiceCollection services)
{
...
services.AddDbContext<DatabaseModel>(options => options.UseMySQL(Configuration.GetConnectionString("Dev")));
...
}
使用 Nuget 安装到数据项目中
MySQL.Data.EntityFrameworkCore v8.0.22
(this installs Microsoft.EntityFrameworkCore.Relational and MySql.Data)
我无法引用 using MySQL.Data.EntityFrameworkCore.Extensions;,因为我收到一个错误(Extensions 下的红线),所以有些东西没有被引用,但编译正常。
在DatabaseModel.cs数据项目中
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
{
....
}
有什么想法吗?我在 ASP.Net 中使用过 MySQL,但没有在 Core 中使用过,所以我认为我缺少包但不确定。
【问题讨论】:
标签: c# mysql asp.net-core entity-framework-core