sjh37 / EntityFramework-Reverse-POCO-Code-First-Generator

EntityFramework Reverse POCO Code First Generator - Beautifully generated code that is fully customisable. This generator creates code as if you reverse engineered a database and lovingly created the code by hand. It is free to academics (you need a .edu or a .ac email address), not free for commercial use. Obtain your licence from
https://www.reversepoco.co.uk/
Other
706 stars 230 forks source link

Settings.ConnectionString vs Settings.ConnectionStringName #759

Closed kurt-o-matic closed 2 years ago

kurt-o-matic commented 2 years ago

Sorry to open an issue on this, but I'm having trouble with the connection string configuration. I'm using V3.6.0 with EFCore/.NET 6.

The Settings.ConnectionString value is working great, no problems running the generator. However, the resulting generated code includes the literal value of this connection string hard-coded into the context's OnConfiguring method, which is completely inappropriate. The Settings.ConnectionStringName value I provided does not appear anywhere in the generated code, including the context constructor, as stated in the template comments. The template comments imply that the generator will include the configuration connection string lookup in the context constructor, but I'm not seeing anything like that.

What am I missing? How should a bog-standard asp.net/ef core appsettings.config be integrated with the reverse-engineered context for connection strings? How do I keep hard-coded connection strings out of my source repo (aside from the template itself)?

sjh37 commented 2 years ago

Hi. Have a read of https://github.com/sjh37/EntityFramework-Reverse-POCO-Code-First-Generator/wiki/ConnectionString

And this page https://github.com/sjh37/EntityFramework-Reverse-POCO-Code-First-Generator/wiki/Settings.OnConfiguration

I would say you need to set Settings.OnConfiguration = OnConfiguration.Configuration

kurt-o-matic commented 2 years ago

Thanks, Simon! I knew I was missing something; Settings.OnConfiguration is exactly what I needed. 👍