【发布时间】:2021-01-22 06:06:39
【问题描述】:
在我的项目中,我在实体框架核心中处理两个数据库(SQL 和 Oracle)。我想根据 appsettings.json 中的配置值创建 SQL 和 Oracle 的上下文。 SQL和Oracle DB的表结构都是一样的。
我想知道是否有任何方法可以实现这一目标。下面是我的示例代码。
public class UserRepository: IUserRepository
{
private readonly SQLDBContext _context;
private readonly OraDbContext _contextOracle;
private readonly IConfiguration _config;
private readonly bool _dbSelect;
public UserRepository(SQLDBContext context, IConfiguration config, OraDbContext contextOracle, DbContext contexts)
{
_context = context;
_config = config;
_contextOracle = contextOracle;
_dbSelect = Convert.ToBoolean(config.GetSection("DbType").GetSection("SQLDbConfigured").Value);
}
}
【问题讨论】:
标签: .net .net-core entity-framework-core asp.net-core-webapi