2
In my solution C#
, I use transformation Web.config
to connect a specific data environment, but I’m having a problem with EntityFramework
who can’t recognize string de conexão
transformed, only recognizes the Web.config
leading.
How to solve this problem?
Example of codes below:
Filing cabinet 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>
Filing cabinet 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;
}
...
}
Post your Webconfig, Code you have in your project!
– novic
@Virgilionovic posted it!
– Leandro