EF Core OnConfiguring method

Discussion of open issues, suggestions and bugs regarding Entity Developer - ORM modeling and code generation tool
Post Reply
marton
Posts: 6
Joined: Fri 06 Apr 2018 11:58

EF Core OnConfiguring method

Post by marton » Fri 06 Apr 2018 12:23

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?

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

Re: EF Core OnConfiguring method

Post by Shalex » Fri 06 Apr 2018 18:25

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().

marton
Posts: 6
Joined: Fri 06 Apr 2018 11:58

Re: EF Core OnConfiguring method

Post by marton » Fri 06 Apr 2018 19:40

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.

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

Re: EF Core OnConfiguring method

Post by Shalex » Fri 13 Apr 2018 12:56

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.

marton
Posts: 6
Joined: Fri 06 Apr 2018 11:58

Re: EF Core OnConfiguring method

Post by marton » Tue 17 Apr 2018 07:23

Thank you.

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

Re: EF Core OnConfiguring method

Post by Shalex » Fri 27 Apr 2018 11:27

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.

Post Reply