Page 1 of 1

optionsBuilder.IsConfigured

Posted: Tue 21 Aug 2018 10:34
by entwicklungsensis
Hello all,
i have a problem with the generated code from Entity Developer and dotconnect oracle.
After generation of the context class there is the following code generated:

Code: Select all

        protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
        {
            if (!optionsBuilder.IsConfigured)
            {
                if (!optionsBuilder.Options.Extensions.OfType<RelationalOptionsExtension>().Any(ext => !string.IsNullOrEmpty(ext.ConnectionString) || ext.Connection != null))
                  optionsBuilder.UseOracle(@"User Id=*****;Password=*****;Server=****;Direct=True;Service Name=orcl;Persist Security Info=True);
            }
            CustomizeConfiguration(ref optionsBuilder);
            base.OnConfiguring(optionsBuilder);
        }
When i start the application i got this error:
System.InvalidOperationException: No database provider has been configured for this DbContext. A provider can be configured by overriding the DbContext.OnConfiguring method or by using AddDbContext on the application service provider. If AddDbContext is used, then also ensure that your DbContext type accepts a DbContextOptions<TContext> object in its constructor and passes it to the base constructor for DbContext.

This is because the optionsBuilder.IsConfigured is true.
So the optionsBuilder.UseOracle(...) is never reached.

Why does the optionsBuilder.IsConfigured is true?
What is the best way to get this to work?
For sure i can delete the if (!optionsBuilder.IsConfigured) after every generation but i think thats not the right way?!

Thanks for any help
Kind Regards
Thomas

Re: optionsBuilder.IsConfigured

Posted: Mon 27 Aug 2018 15:13
by Shalex
We have asked for a test project for reproducing by email.

Re: optionsBuilder.IsConfigured

Posted: Thu 06 Sep 2018 07:51
by entwicklungsensis
Send a project. Error is reproduced. Waiting for solution...

Re: optionsBuilder.IsConfigured

Posted: Fri 07 Sep 2018 14:12
by Pinturiccio
As we answered in email, we have reproduced the issue. We will investigate it and post here about the results as soon as possible.

Re: optionsBuilder.IsConfigured

Posted: Thu 20 Sep 2018 13:12
by Pinturiccio
We have fixed the bug with "No database provider has been configured for this DbContext." in the DbContext template for EF Core.

New build of Entity Developer 6.3.582 is available for download!
It can be downloaded from https://www.devart.com/entitydeveloper/download.html (trial version) or from Customer Portal (for users with valid subscription only).
For more information, please refer to viewtopic.php?t=37707

Re: optionsBuilder.IsConfigured

Posted: Thu 20 Sep 2018 13:14
by Pinturiccio
We have also added an additional constructor that accepts DbContextOptions as an argument to the DbContext class descendant in the VB.NET version of the DbContext template for EF Core.