【问题标题】:Dividing entity framework connection string into 2 parts将实体框架连接字符串分成两部分
【发布时间】:2023-03-13 01:09:02
【问题描述】:

我正在尝试为遗留项目设置持续集成。在 Web.config 中,有 Entity Framework 连接字符串:

<add name="StuffContext" 
     connectionString="
       metadata=res://*/Stuff.csdl|res://*/Stuff.ssdl|res://*/Stuff.msl;
       provider=System.Data.SqlClient;
       provider connection string=&quot;
         data source=mydbserver;
         initial catalog=mydb;
         persist security info=True;
         user id=loki2302;
         password=qwerty;
         multipleactiveresultsets=True;
         App=EntityFramework&quot;" 
       providerName="System.Data.EntityClient" />

有没有办法以某种方式提取provider connection string 并在StuffContext 连接字符串中按名称引用它?试图实现这样的目标:

...
<add name="StuffContext" 
     connectionString="metadata=...;name=StuffDb" />

<add name="StuffDb"
     connectionString="
       data source=mydbserver;
       initial catalog=mydb;
       persist security info=True;
       user id=loki2302;
       password=qwerty;
       multipleactiveresultsets=True;
       App=EntityFramework" />
...

【问题讨论】:

    标签: .net entity-framework web-config connection-string


    【解决方案1】:

    不在web.config 中,不,但您当然可以使用EntityConnectionStringBuilder

    【讨论】:

    • 我明白你想要什么,但我告诉你什么是可能的。
    • 另一种可能的解决方案是 web.config 转换,这不是您所要求的,但可能会解决您的实际问题。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2010-10-25
    • 2011-11-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-10-11
    相关资源
    最近更新 更多