Set Oracle Configuration Settings in EF Core DBContext — oracle-tech

    Forum Stats

  • 3,715,652 Users
  • 2,242,820 Discussions
  • 7,845,479 Comments

Discussions

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Set Oracle Configuration Settings in EF Core DBContext

user613363
user613363 Member Posts: 9 Blue Ribbon
edited February 2020 in ODP.NET

I am using Oracle.EntityFramework.Core 2.19.50. UPDATE: I have learned a few things.  I have put most of the configurations in the Startup.cs file.

This is how I did it in Oracle.Managed.EntityFramework:

    using System.Data.Entity;

    public class AppsDbContext : DbContext

    {

        public AppsDbContext()

            : base("name=AppsDbContext")

        {

            this.Configuration.AutoDetectChangesEnabled = false;

            this.Configuration.LazyLoadingEnabled = false;

            this.Configuration.ProxyCreationEnabled = false;

            this.Configuration.UseDatabaseNullSemantics = true;

            this.Configuration.ValidateOnSaveEnabled = false;

            Database.SetInitializer<AppsDbContext>(null);

         

        }

        public DbSet<AppsAccess> AppsAccessData { get; set; }

        public DbSet<EmployeeAccess> EmployeeAccess { get; set; }

     

        protected override void OnModelCreating(DbModelBuilder modelBuilder)

        {

            modelBuilder.HasDefaultSchema("XYZ");                

        }    

    }

}

For EF Core:

Startup.cs

services.AddEntityFrameworkOracle()

    .AddDbContext<OracleDbContext>(builder => builder

     .UseOracle(Configuration["Data:OracleDbContext"],providerOptions => providerOptions.CommandTimeout(60).UseRelationalNulls(true).MinBatchSize(2))

     .EnableDetailedErrors(false).EnableSensitiveDataLogging(false)

     .UseQueryTrackingBehavior(QueryTrackingBehavior.NoTracking),ServiceLifetime.Scoped);

OracleConfiguration.StatementCacheSize = 300;

OracleConfiguration.FetchSize = 300000;

:

Here's my DbContext:

using Microsoft.EntityFrameworkCore;

public class AppsDbContext : DbContext

    {

        public AppsDbContext(DbContextOptions<AppsDbContext> options): base(options)

        {

            this.ChangeTracker.LazyLoadingEnabled = false;          

        }

         public AppsDbContext() {

            this.ChangeTracker.LazyLoadingEnabled = false;          

        }

        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)

        {

            optionsBuilder.UseOracle(connectionString: "myconnectioninfo");

        }

        protected override void OnModelCreating(ModelBuilder modelBuilder)

        {

            modelBuilder.HasDefaultSchema("ZZZ");

        }

        public DbSet<AppsAccess> AppsAccess { get; set; }

        public DbSet<EmployeeAccess> EmployeeAccess { get; set; }           

    }

Best Answer

Answers

Sign In or Register to comment.