将实体框架连接字符串分为两部分

时间:2013-05-14 11:33:41

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

我正在尝试为旧项目设置持续集成。在Web.config中,有实体框架连接字符串:

<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" />
...

1 个答案:

答案 0 :(得分:0)

不在web.config,不在,但您当然可以使用EntityConnectionStringBuilder进行此操作。