简体   繁体   English

无法连接到 aspnet core webapi 中的 Oracle Db

[英]Unable to connect to Oracle Db in aspnet core webapi

I create a project with dotnet core using webapi template.我使用 webapi 模板创建了一个带有 dotnet 核心的项目。 I'm trying to connect my API with a Oracle database using Citms.EntityFrameworkCore.Oracle package, since the official package isn't free.我正在尝试使用 Citms.EntityFrameworkCore.Oracle 包将我的 API 与 Oracle 数据库连接,因为官方包不是免费的。 But every time I start the API, I have the following error on但是每次启动API时,都会出现以下错误

context.Set<TEntity>();

GenericRepository.cs GenericRepository.cs

public GenericRepository(ApplicationDbContext context)
{
    this.Context = context;
    this.DbSet = context.Set<TEntity>();
}

Error:错误:

System.MissingMethodException: 'Method not found: 'Void Microsoft.EntityFrameworkCore.Storage.Internal.RelationalCommandBuilderFactory..ctor(Microsoft.EntityFrameworkCore.Diagnostics.IDiagnosticsLogger`1<Command>, 

Startup.cs启动文件

public void ConfigureServices(IServiceCollection services)
{
    services.AddMvc().SetCompatibilityVersion(CompatibilityVersion.Version_2_1);

    services.AddDbContext<ApplicationDbContext>(options =>
    {
        //options.UseMySql(Configuration.GetConnectionString("DefaultConnection"));
        options.UseOracle(@"DATA SOURCE = <CONNECTION_STRING>");
    });

    services.AddSwagger();

    //services.AddScoped<IValuesRepository, ValuesRepository>();
    services.AddScoped<IValueService, ValueService>();

    var corsBuilder = new CorsPolicyBuilder();
    corsBuilder.AllowAnyHeader();
    corsBuilder.AllowAnyMethod();
    corsBuilder.AllowAnyOrigin(); 
    corsBuilder.AllowCredentials();

    services.AddCors(options =>
    {
        options.AddPolicy("SiteCorsPolicy", corsBuilder.Build());
    });
}

That's a bug in the package you use, it uses internal Entity Framework code that has been modified, and now it no longer works correctly.这是您使用的包中的一个错误,它使用已修改的内部实体框架代码,现在它不再正常工作。

See this similar issue for the Pomelo.EntityFrameworkCore.MySql package, where an EF developer responded with:请参阅 Pomelo.EntityFrameworkCore.MySql 包的类似问题,其中 EF 开发人员回应:

@AdamDotNet Thanks for reporting this. @AdamDotNet 感谢您报告此事。 It is happening because the MySQL provider is making use of EF Core internal code--I filed this issue for that: PomeloFoundation/Pomelo.EntityFrameworkCore.MySql#497这是因为 MySQL 提供程序正在使用 EF Core 内部代码——我为此提交了这个问题:PomeloFoundation/Pomelo.EntityFrameworkCore.MySql#497

From the EF side, we will discuss in triage whether or not to revert this change to the internal code, but the long term solution is for the provider to stop using internal code.从 EF 方面,我们将在分类中讨论是否将此更改还原为内部代码,但长期解决方案是提供商停止使用内部代码。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM