EntityFramework does not recognize Web transformation Config

1

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=&quot;data source=BBBBBBB;initial catalog=CapCob;persist security info=True;user ID=xxxyyy;password=xxx;MultipleActiveResultSets=True;App=EntityFramework&quot;" 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=&quot;data source=ABCDEF;initial catalog=CapCob;persist security info=True;user ID=USERA;password=xxx;MultipleActiveResultSets=True;App=EntityFramework&quot;" 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;
        }
        ...
}
    
asked by anonymous 15.09.2016 / 16:32

1 answer

0

In the web.HML.config file, it would be a configuration file of your application when a project (compilation) of your project was generated, so when a compilation was generated from this web.HML.config , a Web.config is created % with specifications of web.HML.config .

According to the link :

Save and close the transformation file.

When you deploy the Webaplacing using the selected build configuration and using a one-click publishing deployment package, Web.config file is transformed to its specifications.

Reference How to: Transform Web.config When Deploying a Web Application Project

In this same text says that Visual Studio creates a default configuration file for Debug and Release but nothing prevents you from creating your own, but that this is only modified when a build of the project is generated with the choice of the Visual Studio configuration file ( Web.config ) or some other file created by the developer. >

To make a publication of your project, right click on the name of your project and select Publish and follow the step by step in the sub menu.

Inthetestsrun,itdoesnotreallywork,butwhenIgeneratedtheprojectbuild(Publish)InoticedthatitmadethetransformationtoWeb.ConfigthatIselected.

Theadditionalfilescreated,likeconfigurationforexampletoacertainserverthathasaconnectionwithadifferentbankthantheoneinthelocalmachineofdevelopment,beingusefulalreadysincetheconfigurationofbankwhenwecreatedthepagesalmosttheyareneverthesameastheserver,itwouldbeaformofcreationaccordingtotheserverused.

Links:

15.09.2016 / 22:27