【发布时间】:2022-04-27 10:08:02
【问题描述】:
我正在尝试将我在 asp.net 6 中构建的 Web API 与 MySql 连接,我遇到了很多麻烦
我的服务看起来像这样
builder.Services.AddDbContext<TicketApiContext>(options =>
options.UseMySQL("CONNECTION_STRING"));
我的数据库上下文是这样的。
using Microsoft.EntityFrameworkCore;
namespace VelocityNetAPI.Data
{
public class TicketApiContext : DbContext
{
public TicketApiContext(DbContextOptions<TicketApiContext> options)
: base(options)
{
}
public DbSet<VelocityNetAPI.Models.Client> Client { get; set; }
public DbSet<VelocityNetAPI.Models.Job> Job { get; set; }
public DbSet<VelocityNetAPI.Models.User> User { get; set; }
public DbSet<VelocityNetAPI.Models.Dev> Dev { get; set; }
public DbSet<VelocityNetAPI.Models.FinishedJobs> FinishedJobs { get; set; }
}
}
当我运行 add-migration initial 时出现错误
Unable to resolve service for type 'Microsoft.EntityFrameworkCore.Storage.TypeMappingSourceDependencies' while attempting to activate 'MySql.EntityFrameworkCore.Storage.Internal.MySQLTypeMappingSource'.
请帮助我完全迷路了
大家干杯
【问题讨论】:
-
是否也安装了所有依赖项?您不需要 SQLServer 包,除非您同时针对两个数据库。您是否尝试过使用 v5 而不是 v6?例如stackoverflow.com/questions/70224907/… 之类的问题
-
没有使用Sql Server,因为服务配置为mysql。我还没有尝试过从 MySql 6 到 5 我现在这样做了
-
尝试使用
Pomelo.EntityFrameworkCore.MySql包 - 它被广泛使用(19M 下载 vs 737K 的 Oracle 包) -
我找到了一个使用 pomelo 的存储库,所以我会尽快尝试。为帮助的小伙子欢呼
标签: c# mysql asp.net webapi .net-6.0