请问这是怎么设置上下文的连接字符串使用CloudConfigurationManager? [英] Is this how to set Context Connection String Using CloudConfigurationManager?
问题描述
我期待使用CloudConfigurationManager这样我就可以利用Azure的配置文件的优势。我想用我添加了一个字符串连接字符串我Cloud.cscfg配置实体框架上下文。
I am looking to use CloudConfigurationManager so I can take advantage of Azure configuration files. I want to use a connection string I added a string to my Cloud.cscfg to configure Entity Framework Context.
我在配置我的上下文是这样
I was configuring my context like this
public DomainContext()
: base("ContextConnectionString")
这是从Web.config采取ContextConnectionString
This was taking the ContextConnectionString from the Web.config
我改变了上下文构造这个
I changed the Context Constructor to this
public DomainContext()
: base(CloudConfigurationManager.GetSetting("ContextConnectionString"))
和现在的作品。
有没有更优雅的方式来告诉我的上下文构造首先使用Azure的cscfg?
Is there a more elegant way to tell my context constructor to use Azure cscfg first?
推荐答案
有当时是不是一个更好的解决方案,没有。事实上,这是颇有几分比你有什么在一个月前就已经写更优雅。在 CloudConfigurationManager
是一类在1.7 SDK新的形成是因为previously有在做这样的事情的支持没有内置。如果你想要做什么 CloudConfigurationMangager
不,现在你必须创建自己的类,这是<一个href=\"http://stackoverflow.com/questions/9177413/azure-class-library-access-getconfigurationsettingvalue-vs-web-config\">$p$ptty常见。
There is not a more elegant solution at the moment, no. In fact this is quite a bit more elegant than what you would have had to have written a month ago. The CloudConfigurationManager
is a class that is new in the 1.7 SDK and was created because previously there was no built in support for doing this sort of thing. If you wanted to do what CloudConfigurationMangager
does now you had to create your own class, which was pretty common.
这篇关于请问这是怎么设置上下文的连接字符串使用CloudConfigurationManager?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!