无法从“字符串”转换为“Microsoft.EntityFrameworkCore.ServerVersion”

c#

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


以上是无法从“字符串”转换为“Microsoft.EntityFrameworkCore.ServerVersion”的全部内容。
THE END
分享
二维码
< <上一篇
下一篇>>