Files
zszq-trs/YLErpDAL/DataBase/APEXOracleContext.cs
T
2024-05-09 14:06:26 +08:00

43 lines
1.4 KiB
C#

using Microsoft.Extensions.Logging;
using YLErp.DataBase.Interceptors;
namespace YLErp.DataBase
{
public class APEXOracleContext:DbContext
{
private LogLevel _logLevel;
[System.Diagnostics.Conditional("DEBUG")]
public void SetDebugLog()
{
_logLevel = LogLevel.Debug;
}
protected string GetConnectionString() => AppManager.GetConnectionString("apex_oracle");
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
{
var connectionString = GetConnectionString();
optionsBuilder.LogTo(log =>
{
if (_logLevel == LogLevel.Debug)
{
System.Diagnostics.Debug.WriteLine(log);
}
});
if (_logLevel == LogLevel.Debug)
{
optionsBuilder.AddInterceptors(DgDbCommandInterceptor.Default);
}
optionsBuilder.UseOracle(connectionString);
}
protected override void OnModelCreating(ModelBuilder modelBuilder)
{
modelBuilder.HasDefaultSchema(Environment.GetEnvironmentVariable("OrcaleDatabaseConfig_Schema")); // 设置默认模式
// 配置实体和其他模型设置
}
// 声明数据库中的实体集合
public DbSet<AMR_N042_ENT_BASEINFO_COPY> ClientAMRNetBaseInfos { get; set; }
}
}