内核中的错误"The call is ambiguous between the following methods or properties : UseMySql" asp.net



以下方法或属性之间的调用不明确:'Microsoft.EntityFrameworkCore.MySQLDbContextOptionsExtensions.UseMySQL(Microsoft.EntityFrameworks Core.DbContext OptionsBuilder,一串System.Action<MySql.EntityFrameworkCore.Infrastructure.MySQLDbContextOptionsBuilder>('和'Microsoft.EntityFrameworkCore.MySQLDbContextOptionsExtensions.UseMySQL(Microsoft.EntityFrameworks Core.DbContext OptionsBuilder,一串System.Action<MySql.Data.EntityFrameworkCore.Infrastructure.MySQLDbContextOptionsBuilder>('

我的代码是

public void ConfigureServices(IServiceCollection services)
{
services.AddDbContextPool<ProjectDataContext>(options => options.UseMySQL(_config.GetConnectionString("DefaultConnection")));
services.AddMvc();
}

从错误中可以清楚地看出,您引用的是using部分中的两个包:

using MySql.EntityFrameworkCore.Infrastructure.MySQLDbContextOptionsBuilder;
using MySql.Data.EntityFrameworkCore.Infraestructure.MySQLDbContextOptionsBuilder;

要解决此问题,请删除不想使用的方法,或者(如果类中需要两者(直接调用所需的方法,而不是作为扩展方法。例如:

services.AddDbContextPool<ProjectDataContext>(options =>
MySql.EntityFrameworkCore.Infrastructure.MySQLDbContextOptionsBuilder.UseMySQL(options, _config.GetConnectionString("DefaultConnection")));

//或

services.AddDbContextPool<ProjectDataContext>(options =>
MySql.Data.EntityFrameworkCore.Infraestructure.MySQLDbContextOptionsBuilder.UseMySQL(options, _config.GetConnectionString("DefaultConnection")));

相关内容

最新更新