标签:this orm nal tab 连接 判断 connect rri summary
1.添加包引用:
Microsoft.EntityFrameworkCore.Relational
Oracle.EntityFrameworkCore
2.重写DbContext OnModelCreating
/// <summary> /// 判断如果是Oracle,需要执行Schema /// </summary> /// <param name="modelBuilder"></param> protected override void OnModelCreating(ModelBuilder modelBuilder) { //判断当前数据库是Oracle 需要手动添加Schema(DBA提供的数据库账号名称) if (this.Database.IsOracle()) { modelBuilder.HasDefaultSchema(new SqlConnectionStringBuilder(Database.GetDbConnection().ConnectionString).UserID.ToUpper()); } base.OnModelCreating(modelBuilder); }
3.在DbContextConfigurer 中启用oracle连接
public static class EzxDbContextConfigurer { public static void Configure(DbContextOptionsBuilder<EzxDbContext> builder, string connectionString) { //builder.UseSqlServer(connectionString); builder.UseOracle(connectionString); } public static void Configure(DbContextOptionsBuilder<EzxDbContext> builder, DbConnection connection) { builder.UseSqlServer(connection); } }
4.在appsettings.json中添加Oracle的字符串的配置
{ "ConnectionStrings": { //"Default": "Server=localhost; Database=EzxDb; Trusted_Connection=True;" "Default": "User Id=cis;Password=cis;Data Source=127.0.0.1:1521/hisbd" }, "Authentication": { "JwtBearer": { "IsEnabled": "true", "SecurityKey": "Ezx_C421AAEE0D114E9C", "Issuer": "Ezx", "Audience": "Ezx" } }, "Logging": { "IncludeScopes": false, "LogLevel": { "Default": "Debug", "System": "Information", "Microsoft": "Information" } } }
标签:this orm nal tab 连接 判断 connect rri summary
原文地址:https://www.cnblogs.com/wu-dy/p/12885748.html