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
700 stars 230 forks source link

How to read connection string from user secrets in database.tt file. #799

Closed SatishPaiB closed 1 year ago

SatishPaiB commented 1 year ago

Hi @sjh37 Is there any way, instead of reading the direct connection string in the database.tt, I can use user secrets to get the connection string.

image

instead of connnecting string, I can write code, such as extracting the value from user secerts such as what we write in startup.cs or program.cs.

image

It will be helpful if you give me something in asp.net 6.0.

Thank you very much.

sjh37 commented 1 year ago

I got it working with setting an environment variable conn to my connection string. image

And using the following in <database>.tt

Settings.ConnectionString = Environment.GetEnvironmentVariable("conn", EnvironmentVariableTarget.User);
sjh37 commented 1 year ago

Just realised I already had a wiki article on it here: wiki - ConnectionString

SatishPaiB commented 1 year ago

@sjh37 thank you very much.