In my solution C#
, I use Web.config
transformation to connect a specific data environment, but I'm having a problem with EntityFramework
that can not recognize string de conexão
transformed , only recognizes Web.config
primary .
How do I solve this problem?
Example of codes below:
File web.config
<connectionStrings>
<add name="ConexCobranca" connectionString="Data Source=BBBBBBB;Initial Catalog=CapCob;User ID=xxxyyy;Password=xxx" providerName="System.Data.SqlClient" />
<add name="DbCobCapEntidades" connectionString="metadata=res://*/ModeloCobranca.csdl|res://*/ModeloCobranca.ssdl|res://*/ModeloCobranca.msl;provider=System.Data.SqlClient;provider connection string="data source=BBBBBBB;initial catalog=CapCob;persist security info=True;user ID=xxxyyy;password=xxx;MultipleActiveResultSets=True;App=EntityFramework"" providerName="System.Data.EntityClient" />
</connectionStrings>
File web.HML.config
<?xml version="1.0" encoding="utf-8"?>
<configuration xmlns:xdt="http://schemas.microsoft.com/XML-Document-Transform">
<connectionStrings>
<add name="ConexCobranca" connectionString="Data Source=ABCDEF;Initial Catalog=CapCob;User ID=USERA;Password=xxx" xdt:Transform="SetAttributes(connectionString)" xdt:Locator="Match(name)" />
<add name="DbCobEntidades" connectionString="metadata=res://*/ModeloCobranca.csdl|res://*/ModeloCobranca.ssdl|res://*/ModeloCobranca.msl;provider=System.Data.SqlClient;provider connection string="data source=ABCDEF;initial catalog=CapCob;persist security info=True;user ID=USERA;password=xxx;MultipleActiveResultSets=True;App=EntityFramework"" xdt:Transform="SetAttributes(connectionString)" xdt:Locator="Match(name)" />
</connectionStrings>
<system.web>
<compilation xdt:Transform="RemoveAttributes(debug)" />
</system.web>
</configuration>
Cobranca.EDMX
public partial class DbCobEntidades : ObjectContext
{
#region Constructors
/// <summary>
/// Initializes a new DbCobEntidades object using the connection string found in the 'DbCobEntidades' section of the application configuration file.
/// </summary>
public DbCobEntidades() : base("name=DbCobEntidades", "DbCobEntidades")
{
this.ContextOptions.LazyLoadingEnabled = true;
}
...
}