Skip to Main Content

ODP.NET

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Set Oracle Configuration Settings in EF Core DBContext

user613363Feb 7 2020 — edited Feb 8 2020

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; }           

    }

This post has been answered by Alex Keh-Oracle on Feb 8 2020
Jump to Answer
Comments
Post Details
Added on Feb 7 2020
1 comment
6,186 views