gpt4 book ai didi

c# - 无法从 'string' 转换为“Microsoft.EntityFrameworkCore.ServerVersion”

转载 作者:行者123 更新时间:2023-12-03 23:39:26 29 4
gpt4 key购买 nike

我正在使用 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; }
}
}
}

最佳答案

public class BotContext : DbContext 
{
public DbSet<Server> Servers { get; set; }
public BotContext()
{
Database.EnsureCreated();
}

protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
optionsBuilder.UseMySql(
"server=localhost;user=root;port=3306;Connect Timeout=5;",
new MySqlServerVersion(new Version(8, 0, 11))
);
}

public class Server
{
public ulong Id { get; set; }
public string Prefix { get; set; }
}
}
这应该会有所帮助: https://metanit.com/sharp/entityframeworkcore/7.2.php

关于c# - 无法从 'string' 转换为“Microsoft.EntityFrameworkCore.ServerVersion”,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/66720614/

29 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com