Page 1 of 1

EF Core OnConfiguring method

Posted: Fri 06 Apr 2018 12:23
by marton
The generator always adds the following lines to the OnConfiguring method:

Code: Select all

if (!optionsBuilder.Options.Extensions.OfType<RelationalOptionsExtension>().Any(ext => !string.IsNullOrEmpty(ext.ConnectionString) || ext.Connection != null))
   optionsBuilder.UseSqlServer(@"Data Source=(localdb)\MSSQLLocalDB;Initial Catalog=xxx;Integrated Security=True;Persist Security Info=True");
(Our problem with this, we cannot initialize the database with InMemory mode, because it checks for connection string or connection and if not present add SqlServer as provider.).

This behavior is not good for us. I can't adjust the options to skip this step.

Is there any ways to achieve this?

Re: EF Core OnConfiguring method

Posted: Fri 06 Apr 2018 18:25
by Shalex
We will notify you when a code generation is improved to cover this case.

As a temporary workaround, you can modify a predefined template to remove generation of optionsBuilder.UseSqlServer().

Re: EF Core OnConfiguring method

Posted: Fri 06 Apr 2018 19:40
by marton
Thank you for the quick response, Shalex.
We really like your tool. We customized the template and added a new condition to the if:
!optionsBuilder.IsConfigured && ...

But I think it would be the best if the initialization could be completely opted-out.

Re: EF Core OnConfiguring method

Posted: Fri 13 Apr 2018 12:56
by Shalex
marton wrote: Fri 06 Apr 2018 19:40We customized the template and added a new condition to the if:
!optionsBuilder.IsConfigured && ...
We have added this condition to a predefined template. We will notify you when the new public build of Entity Developer is available for download.

Re: EF Core OnConfiguring method

Posted: Tue 17 Apr 2018 07:23
by marton
Thank you.

Re: EF Core OnConfiguring method

Posted: Fri 27 Apr 2018 11:27
by Shalex
The check of conditions for setting optionsBuilder.Use... in the generated OnConfiguring method by the EF Core template is improved: viewtopic.php?f=32&t=37084.