2

We are using EF-6 in our web roles & worker roles. These roles are encapsulated into a single cloud service project.

In order to manage config settings in a better way, we have moved most of our config keys into cloud project & we read them using CloudConfigurationManager.

But for packages like Entity Framework or Enterprise Library we can't tell AppDomain to read settings from Cloud Config file. EF looks into respective App.Config or Web.Config of the project.

Is there any way to tell EF to read connection strings from cloud config file?

Abhijeet
  • 13,562
  • 26
  • 94
  • 175
  • EF will use the connection string that it built the model with, but you can customize this by overriding the generated behavior. I think if you provided some code as to what you have or what you would like to do it would be easier to answer. – jamesSampica Aug 08 '14 at 16:35

1 Answers1

3

You could change the T4 template file Model.Context.tt to use

base(CloudConfigurationManager.GetSetting("YourEntities"))

When you regen your model the resulting Model.Context.cs file will use the CloudConfigurationManager.

Beau
  • 419
  • 5
  • 13
  • 1
    How do I specify `providerName` in this case? – Abhijeet Aug 11 '14 at 06:16
  • Similar questions that might help [Is this how to set Context Connection String Using CloudConfigurationManager?](http://stackoverflow.com/questions/11199958/is-this-how-to-set-context-connection-string-using-cloudconfigurationmanager) and [Entity Framework DbContext in Azure Web Role](http://stackoverflow.com/questions/17679088/entity-framework-dbcontext-in-azure-web-role) – Beau Aug 11 '14 at 23:52
  • In my case it was the Model.Context.Context.tt file, and I also had to add the azure using: `using Microsoft.Azure;` – mako Feb 02 '18 at 00:30