optionsBuilder.IsConfigured

Discussion of open issues, suggestions and bugs regarding ADO.NET provider for Oracle
Post Reply
entwicklungsensis
Posts: 5
Joined: Tue 21 Aug 2018 09:47

optionsBuilder.IsConfigured

Post by entwicklungsensis » Tue 21 Aug 2018 10:34

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

Shalex
Site Admin
Posts: 9543
Joined: Thu 14 Aug 2008 12:44

Re: optionsBuilder.IsConfigured

Post by Shalex » Mon 27 Aug 2018 15:13

We have asked for a test project for reproducing by email.

entwicklungsensis
Posts: 5
Joined: Tue 21 Aug 2018 09:47

Re: optionsBuilder.IsConfigured

Post by entwicklungsensis » Thu 06 Sep 2018 07:51

Send a project. Error is reproduced. Waiting for solution...

Pinturiccio
Devart Team
Posts: 2420
Joined: Wed 02 Nov 2011 09:44

Re: optionsBuilder.IsConfigured

Post by Pinturiccio » Fri 07 Sep 2018 14:12

As we answered in email, we have reproduced the issue. We will investigate it and post here about the results as soon as possible.

Pinturiccio
Devart Team
Posts: 2420
Joined: Wed 02 Nov 2011 09:44

Re: optionsBuilder.IsConfigured

Post by Pinturiccio » Thu 20 Sep 2018 13:12

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

Pinturiccio
Devart Team
Posts: 2420
Joined: Wed 02 Nov 2011 09:44

Re: optionsBuilder.IsConfigured

Post by Pinturiccio » Thu 20 Sep 2018 13:14

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.

Post Reply