【发布时间】:2021-06-17 14:18:59
【问题描述】:
我正在使用 C# 并且有一个错误:
Argument 2: cannot convert from 'string' to 'Microsoft.EntityFrameworkCore.ServerVersion'
using Microsoft.EntityFrameworkCore;
using System;
namespace Infrastructure
{
public class BotContext : DbContext
{
public DbSet<Server> Servers { get; set; }
protected override void OnConfiguring(DbContextOptionsBuilder options)
=> options.UseMySql("server=localhost;user=root;port=3306;Connect Timeout=5;");
public class Server
{
public ulong Id { get; set; }
public string Prefix { get; set; }
}
}
}
【问题讨论】:
-
您使用的是什么 NuGet 包?我认为您使用的是Pomelo,但使用the documentation by MySQL 实例化它,所以选择one 或other...
-
是的,使用 Pomelo。我重写了 Pomelo 文档中的代码,但代码仍然不起作用(同样的错误)
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) { optionsBuilder.UseMySql( "server=localhost;user=root;port=3306;Connect Timeout=5;" ); } -
???您提供的文档和链接清楚地显示了您需要传递的 second 参数......您似乎一直错过它。
-
哈,真的很有帮助!非常感谢!
标签: c# mysql entity-framework-core