title: setting up localDB for Entityframework
body: <p>I have an c# .net 4.0 application which connects to sqlexpress.I want to make the change so that it connects to localDB. I will reuse the same mdf .</p>
  
  <p>Presently the config file has the following entry</p>
  
  <pre><code> &lt;configuration&gt;
   &lt;configSections&gt;
   &lt;section name="entityFramework" type="System.Data.Entity.Internal.ConfigFile.EntityFrameworkSection, EntityFramework, Version=6.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" requirePermission="false" /&gt;
  
   &lt;/configSections&gt;
   &lt;startup&gt;
    &lt;supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.0" /&gt;
   &lt;/startup&gt;
  
     &lt;entityFramework&gt;
       &lt;defaultConnectionFactory type="System.Data.Entity.Infrastructure.SqlConnectionFactory, EntityFramework"&gt;
       &lt;parameters&gt;
        &lt;parameter value="Data Source=.\EMSERVER; Integrated Security=True; MultipleActiveResultSets=True" /&gt;
       &lt;/parameters&gt;
      &lt;/defaultConnectionFactory&gt;
     &lt;providers&gt;
         &lt;provider invariantName="System.Data.SqlClient"   type="System.Data.Entity.SqlServer.SqlProviderServices, EntityFramework.SqlServer" /&gt;
    &lt;/providers&gt;
   &lt;/entityFramework&gt;
  </code></pre>
  
  <p></p>
  
  <p>Also the in the code</p>
  
  <p>string providerName = "System.Data.SqlClient";</p>
  
  <pre><code>        // Initialize the connection string builder for the
          // underlying provider.
          SqlConnectionStringBuilder sqlBuilder =
          new SqlConnectionStringBuilder();
  
          // Set the properties for the data source.
          sqlBuilder.DataSource = serverName;
          sqlBuilder.InitialCatalog = databaseName;
          sqlBuilder.IntegratedSecurity = true;
          sqlBuilder.Enlist = true;
          sqlBuilder.MultipleActiveResultSets = true;
  
          // Build the SqlConnection connection string.
          string providerString = sqlBuilder.ToString();
  
          // Initialize the EntityConnectionStringBuilder.
          EntityConnectionStringBuilder entityBuilder =
          new EntityConnectionStringBuilder();
  
          //Set the provider name.
          entityBuilder.Provider = providerName;
  
          // Set the provider-specific connection string.
          entityBuilder.ProviderConnectionString = providerString;
  
          // Set the Metadata location.
          entityBuilder.Metadata = @"res://*/TrendDataModel.csdl|
          res://*/TrendDataModel.ssdl|
          res://*/TrendDataModel.msl";
  
          return entityBuilder.ToString();
  </code></pre>
  
  <p>Should we have both code and app.config ? How do i change it to connect to test.mdf file which is in c:\temp. or is it enough i change the connection string directly in the code?</p>