Jah*_*han 5 dbcontext entity-framework-core asp.net-core asp.net-core-3.0
我在我的项目中应用了 ASP.NET Core 3.1,我想通过代码优先的方法创建数据库并使用 MySQL。在 startup.cs 文件中,我收到此错误:
CS1061“MySQLDbContextOptionsBuilder”不包含“ServerVersion”的定义,并且没有可访问的扩展方法“ServerVersion”接受“MySQLDbContextOptionsBuilder”类型的第一个参数
我该如何解决?
在startup.cs中:
using Microsoft.EntityFrameworkCore;
using Pomelo.EntityFrameworkCore.MySql.Infrastructure;
public void ConfigureServices(IServiceCollection services)
{
services.AddDbContextPool<Alpha.Web.App.ApplicationDbContext>(options =>
options.UseMySQL(Configuration["ConnectionStrings:DefaultConnection"],
mysqlOptions =>
{
mysqlOptions.ServerVersion(new Version(8, 0, 20), ServerType.MySql);
}));
}
Run Code Online (Sandbox Code Playgroud)
ret*_*tif 17
不确定您拥有哪个版本的 Pomelo 软件包,但其中存在某些重大更改(另请参阅此问题),因此现在您需要以不同的方式对其进行初始化。
例如,如果您希望它自动检测版本:
//_connectionString = _configuration.GetConnectionString("DefaultConnection");
services.AddDbContext<IdentityContext>(
options => options.UseMySql(
_connectionString,
ServerVersion.AutoDetect(_connectionString)
)
);
Run Code Online (Sandbox Code Playgroud)
或者如果您想设置特定版本:
//_connectionString = _configuration.GetConnectionString("DefaultConnection");
services.AddDbContext<IdentityContext>(
options => options.UseMySql(
_connectionString,
new MySqlServerVersion(new Version(8, 0, 21))
)
);
Run Code Online (Sandbox Code Playgroud)
归档时间: |
|
查看次数: |
2653 次 |
最近记录: |