配置实体框架从Azure的CloudConfiguration文件挑连接字符串? [英] Configure Entity Framework to pick connection strings from Azure CloudConfiguration File?

查看:130
本文介绍了配置实体框架从Azure的CloudConfiguration文件挑连接字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们正在使用我们的Web角色和放大器EF-6;辅助角色。这些角色都被封装成一个单一的云服务项目。

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

为了以更好的方式来管理配置设置,我们提出我们的大多数配置键进入云计算项目和放大器;我们读到他们使用 CloudConfigurationManager

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.

但对于像实体框架或我们不能企业库包
  告诉AppDomain中读取云配置文件设置。 EF眺望
  各App.Config中或项目的Web.Config中。

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.

有没有办法告诉EF读取云配置文件的连接字符串?

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

推荐答案

您可以改变T4模板文件Model.Context.tt使用

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

base(CloudConfigurationManager.GetSetting("YourEntities"))

当你回蓝模型所产生的Model.Context.cs文件将使用CloudConfigurationManager。

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

这篇关于配置实体框架从Azure的CloudConfiguration文件挑连接字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆