- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在使用 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/
我已经看到其他人回答了这个错误,但我似乎无法让它工作。我正在尝试本地连接到 SQL Server 数据库项目。 当我执行以下操作时,我在 Open() 上抛出此错误: SqlConnection co
我注意到其他一些人也遇到了同样的问题,但无法找到解决方案。我的 ASP.NET 应用程序运行完美,突然遇到这种情况。它没有抛出任何异常,但存储过程不再像以前那样返回值。当我调试程序时注意到我的 Sql
我打开一个 SqlConnection。 SqlConnection Conn = new SqlConnection(...); Conn.Open(); ... Conn.Close(); Con
我正在使用 C# 并且有一个错误:Argument 2: cannot convert from 'string' to 'Microsoft.EntityFrameworkCore.ServerVe
我在我的项目中应用了 ASP.NET Core 3.1,我想通过代码优先的方法创建数据库并使用 MySQL。 在 startup.cs 文件中,我收到此错误: CS1061 'MySQLDbConte
我有一台装有 Windows 7 (IIS 6.0)、MS SQL Server 2008、Visual Studio 2008 的工作站。我的 SQL Server Management Studi
这个问题在这里已经有了答案: C# console application Invalid Operation Exception (6 个答案) 关闭 3 年前。 我有一个本地 SQL Serve
我正在实现一个将使用 Entity Framework 6 获取数据的 Web API。我正在使用 Sql Server 2014 和 visual studio 2015。在调试 CustomerD
我是一名优秀的程序员,十分优秀!