码迷,mamicode.com
首页 > 数据库 > 详细

ABP .net core集成访问Oracle数据库

时间:2020-05-14 01:52:10      阅读:134      评论:0      收藏:0      [点我收藏+]

标签: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"
    }
  }
}

  

ABP .net core集成访问Oracle数据库

标签:this   orm   nal   tab   连接   判断   connect   rri   summary   

原文地址:https://www.cnblogs.com/wu-dy/p/12885748.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!