gpt4 book ai didi

azure - 这是如何使用 CloudConfigurationManager 设置上下文连接字符串?

转载 作者:行者123 更新时间:2023-12-03 23:48:14 24 4
gpt4 key购买 nike

我希望使用 CloudConfigurationManager,以便可以利用 Azure 配置文件。我想使用连接字符串,我在 Cloud.cscfg 中添加了一个字符串来配置 Entity Framework 上下文。

我像这样配置我的上下文

public DomainContext()
: base("ContextConnectionString")

这是从 Web.config 中获取 ContextConnectionString

我将上下文构造函数更改为此

public DomainContext()
: base(CloudConfigurationManager.GetSetting("ContextConnectionString"))

现在可以了。

是否有更优雅的方法来告诉我的上下文构造函数首先使用 Azure cscfg?

最佳答案

目前没有更优雅的解决方案,没有。事实上,这比您一个月前编写的内容要优雅得多。 CloudConfigurationManager 是 1.7 SDK 中的新类,之所以创建是因为以前没有内置支持执行此类操作。如果您想做 CloudConfigurationMangager 现在所做的事情,您必须创建自己的类,即 pretty common .

关于azure - 这是如何使用 CloudConfigurationManager 设置上下文连接字符串?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11199958/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com